Objective c 为什么我触摸UITableView时它会显示数据?
我有一个UITableView加载一些tweet,所有这些都可以很好地工作,但是当我填充表格时,它不会进入CellForRow方法,直到我触摸表格视图。。。。有人知道怎么解决这个问题吗Objective c 为什么我触摸UITableView时它会显示数据?,objective-c,ios,uitableview,Objective C,Ios,Uitableview,我有一个UITableView加载一些tweet,所有这些都可以很好地工作,但是当我填充表格时,它不会进入CellForRow方法,直到我触摸表格视图。。。。有人知道怎么解决这个问题吗 tab = [[UITableView alloc] initWithFrame:CGRectMake(10, 300, 400, 200) style:UITableViewStylePlain]; tab.dataSource = self; tab.delegate = self; 然后 - (UI
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;
}加载完推文后,请调用此方法:
[tab reloadData];
重新加载tableView数据源。根据我们所知,最好的猜测是您没有将表作为子视图添加到主线程上。这意味着在滚动之前不会进行重绘。尝试在GCD调用中包装addsubview调用,如下所示:
dispatch_async(dispatch_get_main_queue(), ^() {
[self addSubview:tab];
});
将tableview添加为子视图的代码在哪里?就在tab.delegate=self指令之后。。。[自添加子视图:选项卡];然而,表中显示的是无效的。。。就在我触摸它的时候,它被填充了…你正在用后台线程加载这些tweet吗?当我创建表时,这些tweet已经充电了…你用什么方法初始化表?IE这是在主线程上完成的吗?是的,我刚刚用这个函数在几秒钟前解决了它。。。但答案是否正确:)