如何创建一个UITableView细胞,而不使用dequeueReusableCellWithIdentifier
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Cell *cell = (ChannelViewTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
NSString *channelName;
channelName= [NSString stringWithFormat:@"Enter Channel %ld Name", (long)indexPath.row+1];
indexPathRow= indexPath.row+1;
return cell;
}
您可以通过使用
[UITableViewCell alloc] initWithStyle:<#(UITableViewCellStyle)#> reuseIdentifier:<#(nullable NSString *)#>]
但已经@MuraliMohan和@Larme说我们dequee避免不必要的细胞的产生,以提高性能创建一个。
这样做很简单,我们假设您有100个单元可以显示。由于设备屏幕对于所有用户来说最多只能显示15个单元格,而不会出现,所以您将生成100个单元格并显示15.当单元格离开操作系统屏幕时,会出现什么情况?重复使用它为下一个单元格显示,而不是100你将只有16个单元格的内存。
基本上,只要保持dequeing但如果你想尝试在一个测试应用程序产生大量细胞,而不dequeing,看看性能如何减小;)
谢谢,我知道它会影响性能。但我只需要6格。 –
我相信,即使只有6个,建议使用deque作为操作系统将照顾创建单元格,如果没有人可用,并且您不失去或获取任何东西dequeing,最终由您决定什么使用。 – andecoder
hmmmmm :) :) :) –
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"TableViewCell" forIndexPath:indexPath];
cell.NumberLabel.text =[NSString stringWithFormat:@"Enter Channel %ld Name", (long)indexPath.row+1];
cell.Name.tag = indexPath.row;
NSString *dicKey = [NSString stringWithFormat:@"%ld", (long)indexPath.row];
if (self.cellTextFiledValues[dicKey])
cell.channelName.text = self.cellTextFiledValues[dicKey];
else
cell.channelName.text = @"";
cell.selectionStyle =NO;
return cell;
}
- (void)resetTableview{
self.cellTextFiledValues = [NSMutableDictionary dictionary];
[self.channelViewTableView reloadData];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
totalChannelCount =[self.datacount.text intValue];
NSString *dicKey = [NSString stringWithFormat:@"%ld", (long)textField.tag];
[self.cellTextFiledValues setObject:textField.text forKey:dicKey];
[self.myTableview reloadData];
}
告诉我为什么你想创建一个没有呢? – MuraliMohan
你为什么不想用dequeue?这是优化。如果遇到问题,可能是因为你做错了什么。解释一下,我们可以提供适当的帮助。 – Larme