JSON 개체를 다운로드하고 구문 분석하여 "뉴스 피드"를 작성하여 UITableView를 채 웁니다. 나는 connectionDidFinishLoading의 대리자 메서드에있는 코드의 매우 마지막 줄은 다음과 같습니다 그러나connectionDidFinishLoading 완료 후 UITableView를 다시로드 할 수 없습니다.
[tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
, 내 브레이크 포인트에서 - (있는 UITableViewCell *)있는 tableView : (jQuery과 *) mytableView cellForRowAtIndexPath : (NSIndexPath *) indexPath 방법은 맞지 않았다. (응용 프로그램이 처음 시작될 때 히트됩니다.)
주 스레드에서 reloadData를 호출하고 있는데도 이유는 무엇입니까? 발사하는 것처럼 보이지 않습니다. 그냥 [tableView reloadData] 시도하고 작동하지 않았다. 여기
#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)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];
}
내 헤더 파일 : 여기에
내 connectionDidFinishLoading 방법입니다
- (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
예 Ray, 확실히 다음과 같이 보입니다. 인쇄 : Tableview is (null) – Flea
이것이 사실 인 이유는 확실하지 않습니다. 나는 클래스 상단에서 @synthesize입니다. – Flea