2015-11-12 53 views
3

我一直在撞墙,因为我以为我在stackoverflow上尝试了所有可能的东西。重新加载数据未调用cellForRowAtIndexPath:

所以目前我创建一个表像这样

- (UITableViewCell *)tableView:(UITableView *)tableView  cellForRowAtIndexPath: (NSIndexPath *)indexPath { 
    NSLog(@"CHECK IF THIS IS CALLED"); 
    static NSString *CellIdentifer = @"CellIdentifier"; 
    CBPeripheral *placeHolder; 

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifer]; 
    // Using a cell identifier will allow your app to reuse cells as they come and go from the screen. 
    if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifer]; 
    } 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     placeHolder = _connectedPeripherals[indexPath.row]; 
     cell.textLabel.text = placeHolder.name; 
    } 
    return cell; 
} 

,我从我调用另一个函数调用[self.tableView reloadData]。我知道它在该函数中被调用,但cellForRowAtIndexPath不会再被调用。

我创建了一个UITableView财产在我的.h文件 @property (strong, nonatomic) UITableView *tableView;

而创建的表像这样

self.tableView = [[UITableView alloc] init]; 
self.tableView.rowHeight = 60.0f; 
self.tableView.delegate = self; 
self.tableView.dataSource = self; 



self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; 
[self.view addSubview:self.tableView]; 
[self.view addConstraints:@[ [HTConstraints leftAlignView:self.tableView 
               toView:self.view 
              withSpacing:5], 

          [HTConstraints topAlignView:self.tableView 
               toView:self.view 
              withSpacing:5], 

          [HTConstraints rightAlignView:self.tableView 
                toView:self.view 
              withSpacing:5], 

          [HTConstraints bottomAlignView:self.tableView 
                toView:self.view 
               withSpacing:5], 
          ]]; 

到目前为止,我已经试过了确保[self.tableView reloadData]是被称为在主线程。确保我的部分没有返回0

编辑 这是我reloadData功能,并通过[[RootViewController sharedInstance] reloadData];和日志打印调用另一个类 当我打电话吧。

- (void)reloadData { 
    NSLog(@"Reloading"); 
    [self.tableView reloadData]; 
} 
+0

更新与具有调用'reloadData'方法您的问题之后。解释何时以及如何调用该方法。 – rmaddy

+0

@rmaddy完成!!!! – user3281743

+0

如何在主线程上调用reloadData? –

回答

-1

设置一个断点内 - (无效)reloadData或尝试添加您的UITableView数据源的数量在你的NSLog。

通常cellForRowAtIndexPath没有得到调用,因为它没有任何显示。

-1

我看到,在您的代码中,您忘记将tableView作为子视图添加到控制器。 添加下面的代码您的tableView的初始化

[self.view addSubview:tableView]; 
+0

对不起,我看到你做到了。也许检查你的'tableView'的框架,如果你的'tableView'的高度等于零,它也会导致问题 – Shamsiddin

相关问题