在viewDidload中实现异步读取数据后,在数组(NSMutableArray)中添加此对象数据,刷新tableView
结果在numberOfRowsInSection可以获取到该数组中的对象,但在cellForRowAtIndexPath中获取到得数组却为空,求大神帮忙看看
- (NSMutableArray *)noticeArray
{
if (!_noticeArray) {
_noticeArray = [NSMutableArray array];
}
return _noticeArray;
}
下面是同过异步请求得到的数据,并添加进数组,刷新tableView
NSMutableArray *noticesArray = [NSMutableArray array];
for (NoticeWithNews *notice in array) {
NoticeResult *model = [[NoticeResult alloc] init];
model.noticeWithNews = notice;
[noticesArray addObject:model];
}
self.noticeArray = noticesArray;
[self.tableView reloadData];
至此都还没出现问题,打印的 self.noticeArray也有添加的对象
下面是numberOfRowsInSection,刷新tableView之后打印的self.noticeArray.count有值。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"%ld",self.noticeArray.count);
return self.noticeArray.count;
}
但是到cellForRowAtIndexPath中打印的self.noticeArray,就一直为空
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
}
NSLog(@"%@",self.noticeArray[indexPath.row]);
return cell;
}
2017-02-02 11:15:31.164 校园新闻[2555:68321] 4
2017-02-02 11:15:31.164 校园新闻[2555:68321] (null)
2017-02-02 11:15:31.165 校园新闻[2555:68321] (null)
2017-02-02 11:15:31.166 校园新闻[2555:68321] (null)
2017-02-02 11:15:31.167 校园新闻[2555:68321] (null)
求大神帮忙解答下,为什么在cellForRowAtIndexPath拿到的数组self.noticeArray会突然变为NULL