objective-c - 为什么当我触摸 UITableView 时会显示数据?

标签 objective-c ios uitableview

我有一个 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/

相关文章:

iphone - 将对象从字典添加到可变数组

ios - 只获取那些没有过期的 Facebook 事件 graph api

ios - 动画边界更改时具有 CALayer 有线效果的自定义 View

ios - 如何实现自动填充凭据提供程序扩展 - iOS 11,swift4

ios - 使自定义 UI 元素不在 TableViewController 中滚动

iphone - 体系结构 i386 的重复符号,找不到相同的类名和文件名

ios - 将 float 数组的数组转换为 UnsafeMutablePointer<UnsafeMutablePointer<Float>>

ios - 将 @objc 方法作为操作添加到按钮并获取 "Argument of ' #selector' 并不引用 '@objc' 方法、属性或初始值设定项”

ios - tableView.setContentOffset 不适用于嵌入在 UIViewcontroller 中的 UITableView

ios - 在 UITableViewController 中使用 UITextView - 点击外部以关闭键盘