Iphone dequeueReusableCellWithIdentifier、自定义UITableViewCell出现问题
我有两个按钮的自定义单元格(这些按钮的功能只是禁用被按下的按钮)。 当我以这种经典方式使用dequeueReusableCellWithIdentifier时:Iphone dequeueReusableCellWithIdentifier、自定义UITableViewCell出现问题,iphone,ios,uitableview,Iphone,Ios,Uitableview,我有两个按钮的自定义单元格(这些按钮的功能只是禁用被按下的按钮)。 当我以这种经典方式使用dequeueReusableCellWithIdentifier时: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; cell = ((MainCell*)[t
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
cell = ((MainCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]);
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"MainCell" owner:self options:nil];
}
return cell;
}
UITableView有1个部分,问题是:在第一个单元格上,当我按下按钮将其禁用,然后向下滚动以显示其他单元格,当我再次向上滚动时,第一个单元格是一个新单元格,并且按钮已启用。
我知道reuseIdentifier用于在已经创建的单元格中不重新创建单元格,但通过这种方式,我丢失了所有不可见的单元格信息
有什么想法吗
提前感谢我也遇到了类似的问题——我认为问题在于,在任何给定的时间,实际上只有可见的单元在内存中,当它重新显示一个旧单元时,它实际上只是将一个新单元出列。我认为解决方案是使用-(void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)单元格for rowatindexpath:(nsindepath*)indepath
委托方法:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
id objectForCell = [self.arrayOfThingsForTableView objectAtIndex:indexPath.row];
if (!objectForCell.button1IsEnabled) {
cell.button1.enabled = NO; //or something along those lines
} else {
cell.button1.enabled = YES; //necessary so that all the other buttons don't disable
}
}
如果有人有更好的解决办法,我真的很高兴听到 使用以下命令:
IGECellBasic *cell = [[[IGECellBasic alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
这只是我的UITableViewCell的子类