我一直在撞牆,因爲我以爲我在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? –