我有一个 UITableView 加载一些推文,一切都很好,但是当我填充表格时,它不会进入 CellForRow 方法,直到我触摸表格 View ......有人知道如何解决这个问题吗?
tab = [[UITableView alloc] initWithFrame:CGRectMake(10, 300, 400, 200) style:UITableViewStylePlain];
tab.dataSource = self;
tab.delegate = self;
然后...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"entra a cellula");
Tweet *t = [tweets objectAtIndex:indexPath.row];
static NSString *MyIdentifier = @"MyIdentifier";
// Try to retrieve from the table view a now-unused cell with the given identifier.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
// If no cell is available, create a new one using the given identifier.
if (cell == nil) {
// Use the default cell style.
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier];
}
cell.textLabel.text = t.screenName;
cell.detailTextLabel.text = t.text;
cell.imageView.image = t.profileImage;
return cell;
最佳答案
根据我们所知,最好的猜测是您没有将表添加为主线程上的 subview 。这意味着在滚动之前不会发生重绘。尝试将 addsubview 调用包装在 GCD 调用中,如下所示:
dispatch_async(dispatch_get_main_queue(), ^() {
[self addSubview:tab];
});
关于objective-c - 为什么当我触摸 UITableView 时会显示数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13013980/