在非UITableViewDelegate的函数中重新使用UITableViewCell
我有一个不同的问题 我正在创建TableViewCells,如下所示:在非UITableViewDelegate的函数中重新使用UITableViewCell,uitableview,Uitableview,我有一个不同的问题 我正在创建TableViewCells,如下所示: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell; UILabel *label = nil; NSString *cellIdentifier = [NSString stringWithFor
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
UILabel *label = nil;
NSString *cellIdentifier = [NSString stringWithFormat:@"Cell_%i", indexPath.row];
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier] autorelease];
//cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier];
label = [[UILabel alloc] initWithFrame:CGRectZero];
[label setLineBreakMode:UILineBreakModeWordWrap];
[label setMinimumFontSize:FONT_SIZE];
[label setNumberOfLines:0];
[label setFont:[UIFont systemFontOfSize:FONT_SIZE]];
[label setTag:1];
[[cell contentView] addSubview:label];
}
return cell;
}
如您所见,我有一些带有标识符的单元格,如“Cell\u 0、Cell\u 1等”
在一个不是TableView方法的函数中,我想通过调用它们的标识符来使用这些单元格。我这样做:
UITableViewCell *cell = [myTableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"Cell_%i", myCellID]];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:[NSString stringWithFormat:@"Cell_%i", myCellID]];
}
UILabel *label = (UILabel*)[cell viewWithTag:1];
我不能这样用吗
我正在尝试更改我试图访问的单元格中标签的颜色,但我无法更改。单元格不是零,但标签始终为零。我该怎么办
我怎么才能知道是我想要的还是空的
NSString *cellIdentifier = [NSString stringWithFormat:@"Cell_%i", indexPath.row];
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
这违背了细胞再利用的全部目的
对于“外观”相同(即具有相同子视图)的所有单元格,应使用相同的单元格标识符,并且仅更改其内容
要获取为特定行创建的单元格,请使用
[tableView cellForRowAtIndexPath:indexPath]
好的,我通过在数组中填充所有indexPath并在调用单元格时从该数组中调用索引路径,解决了我的问题。谢谢你的回答我想我不能很好地回答我的问题。我有一个名为getCellToBeModified的方法。它里面没有不可定义的XPath。但是我需要在这个方法中使用我的细胞。因此,我知道我的单元ID保存在一个可变数组中,我试图使用:UITableViewCell*cell=[myTableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@“cell_%i”,myCellID]]访问该单元;如果(cell==nil){cell=[[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:[nsstringwithformat:@“cell_%i”,myCellID]];}我需要一个包含委托方法的解决方案