当然。您可以创建一次单元格,例如在viewDidLoad:中,然后从tableView:cellForRowAtIndexPath:返回它。cellForRowAtIndexPath仍将被调用,但您只创建/初始化一次单元格。如果您愿意,可以这样创建所有单元格并将它们存储在数组中。当视图卸载时,不要忘记释放这些单元格。
- (void)viewDidLoad
{
[super viewDidLoad];
_myCachedCell = [[UITableViewCell alloc] initWithStyle: UITableViewStylePlain reuseIdentifier: nil];
_myCachedCell.textLabel.text = @"some text";
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if ( indexPath.section == 0 && indexPath.row == 0 )
return _myCachedCell;