JSONオブジェクトをダウンロードして解析して、「ニュースフィード」を作成してUITableViewを作成しています。私はconnectionDidFinishLoadingのデリゲートメソッドを持っているコードの非常に最後の行は次のとおりです。connectionDidFinishLoadingが完了した後にUITableViewをリロードできません
[tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
しかし、中に私のブレークポイント - (UITableViewCellの*)のtableView:(のUITableView *)mytableView cellForRowAtIndexPath:(NSIndexPath *)indexPath方法がされていますヒットしません。 (アプリケーションが最初に起動したときにヒットします)
私はメインスレッドでreloadDataを呼び出していますが、何らかの理由でこれを実行します。それは発砲しているように見えません。私はちょうど[tableView reloadData]を試しても動作しませんでした。ここで
は私のconnectionDidFinishLoading方法であって、ここで
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
//NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSArray *publicTimeline = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
NSUInteger newsStreamCount = [publicTimeline count];
// Initialize the collection and the dictionary
newsItemManager.newsItemCollection = [[NSMutableArray alloc] initWithCapacity:newsStreamCount];
NSMutableArray *dictOfNewsItems = [[NSMutableArray alloc] initWithCapacity:newsStreamCount];
// From the JSON object, parse out the individual news item JSON objects and
// put them into a dictionary.
for (int i = 0; i < newsStreamCount; i++)
{
NSDictionary *item = [publicTimeline objectAtIndex:i];
[dictOfNewsItems addObject:item];
}
// For each news item JSON object, extract out the information we need for our
// news manager class
for (int i = 0; i < newsStreamCount; i++)
{
NSString *userName = [[dictOfNewsItems objectAtIndex:i] valueForKey:@"Title"];
NSString *message = [[dictOfNewsItems objectAtIndex:i] valueForKey:@"Content"];
NSString *imgUrl = [[dictOfNewsItems objectAtIndex:i] valueForKey:@"https://si0.twimg.com/logo_normal.jpg"];
NewsItem *newsItem = [[NewsItem alloc] initWithBasicInfo:userName :message :imgUrl];
[newsItemManager.newsItemCollection addObject:newsItem];
}
[tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
}
は私のヘッダファイルである:ここで
#import <UIKit/UIKit.h>
@interface NewsViewController : UITableViewController
@property (nonatomic, retain) NSMutableArray* newsItemArray;
@property (nonatomic, retain) NSMutableData *responseData;
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@end
は私の実装です:
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.title = @"News";
//self.newsItemArray = [[NSMutableArray alloc] initWithObjects:@"One", @"Two", @"Three", nil];
tableView.rowHeight = 75.0;
responseData = [NSMutableData data];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://blah.com/api/news"]];
(void)[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
おかげで、 ノミ
performSelectorを呼び出すときに何らかの理由でtableViewがnilですか? NSLog(@ "Tableview is%@"、tableView); – Rayfleck
はいレイ、確かにそうです:それは印刷されました:Tableview is(null) – Flea
私はこれがなぜそうであるか分かりません。私はクラスの最上部で@synthesizeです。 – Flea