[英]iphone - when exactly does cellForRowAtIndexPath for table views get called and by what in
我只是有一個關於cellForRowAtIndexPath的基本(菜鳥)問題被調用?
我正在遍歷示例代碼,但沒有在任何地方看到它的顯式調用?
UITableViewComponent類型的任何組件在創建時是否會自動調用此函數?
謝謝
當UITableView顯示時,每行都會調用此方法。 在其中,您將使用特定數據自定義每個單元格以進行顯示。
這是課程參考 。
這是一個示例:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"FriendCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
Item *i = [itemArray objectAtIndex:row];
cell.textLabel.text = [i name];
cell.detailTextLabel.text = [i brewery];
[i release];
return cell;
}
繪制相應的UITableView時,將為每個單元格調用此方法。 傳遞一個索引路徑,並根據節和單元格編號,您的代碼應生成一個UITableViewCell,以顯示在UI中。
您可以在此處查看有關UITableViews如何工作的快速教程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.