UITableViewControllerでデータをリロード/更新するのに問題があります。
ASIHTTPRequestを使用してURLを呼び出し、文字列データを返すメソッドがあります。このデータをテーブルのセルに入れようとしていますが、[self.tableviewreloadData]が機能していません。
ASIHTTPRequestは別のスレッドでタスクを完了すると思っていたので、次のことを試しました。
[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
これも何もしませんでした。
データをリロードするにはどうすればよいですか?私はしばらくの間これに固執しています。
コード:MainViewController.h
#import <UIKit/UIKit.h>
@class ProductClass;
@interface MainViewController : UITableViewController {
ProductClass *item;
}
@property (nonatomic, retain) ProductClass *item;
@end
MainViewController.m
#import "MainViewController.h"
#import "ASIHTTPRequest.h"
#import "ProductClass.h"
@implementation MainViewController
@synthesize item;
- (void) viewDidLoad {
self.title = @"TableView Test";
self.tableView.allowsSelection = NO;
self.item = [[ProductClass alloc] init];
[self callURL];
}
-(void)callURL {
NSURL *url = [NSURL URLWithString:@"http://urlgoeshere.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request {
//Grab the response
NSString *responseString = [request responseString];
//Put the result into the ProductClass item
item.titleOfProduct = responseString;
//This line shows that self.tableview does NOT have an address of 0x0
NSLog(@"%@\n", self.tableView);
//Problem line!!!!!!
[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
//The below lines also do nothing!!!!
//[self.tableView reloadData];
//[[self tableView] reloadData];
}
誰でもアイデアがありますか?私は完全に途方に暮れています。
乾杯、ブレット