Я загружаю и анализирую объекты JSON, чтобы создать «ленту новостей» для заполнения UITableView.Самая последняя строка кода, которую я имею в методе делегата connectionDidFinishLoading:
[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];
}
Спасибо, Блоха