我一直在撞墙,因为我以为我在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];
}
更新与具有调用'reloadData'方法您的问题之后。解释何时以及如何调用该方法。 – rmaddy
@rmaddy完成!!!! – user3281743
如何在主线程上调用reloadData? –