![](/img/trans.png)
[英]How does [self.tableView reloadData] know what data to reload?
[英]why [self.tableView reloadData] does not Work?
這是cellForRowAtIndexPath:方法的代碼。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
if (cell == nil) { cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [array objectAtIndex:row];
return cell;
}
當我使用[self.tableView reloadData];
沒事嗎
作為UITableViewDataSource協議的一部分,您至少需要實現tableView:numberOfRowsInSection:方法,以及tableView:cellForRowAtIndexPath:
您已經完成)。 您還應該實現numberOfSectionsInTableView:
然后,您需要確保您的類實際上已用作數據源:
self.tableView.dataSource = self;
這需要通過Interface Builder或awakeFromNib
或其他類似viewDidLoad:
方法來完成。
您是否檢查數據源和UITableView的委托? 我認為dataSource為零或其他。
嘗試在行的單元格中放置一個斷點,看看在調用reloadData時是否調用了該斷點。 還請檢查是否已對從中填充單元格的數組進行了更改,並確保表視圖已連接到其數據源和委托。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.