Ios 选中时更改UITableViewCell
在我的应用程序中,我有一个UITableView和两个不同的自定义UITableViewCell。UITableView最初加载一种自定义UITableViewCell。当在我的UITableView中选择一个单元格时,我想更改使用其他类型的自定义UITableViewCell选择的单元格。这可能吗?让我听听你得到了什么 谢谢, 恩斯诺兰Ios 选中时更改UITableViewCell,ios,uitableview,Ios,Uitableview,在我的应用程序中,我有一个UITableView和两个不同的自定义UITableViewCell。UITableView最初加载一种自定义UITableViewCell。当在我的UITableView中选择一个单元格时,我想更改使用其他类型的自定义UITableViewCell选择的单元格。这可能吗?让我听听你得到了什么 谢谢, 恩斯诺兰 在didSelectRow…方法中,需要更新一个标志(存储在实例变量中),指示单元格的新“模式”。然后通过调用tableView reloadrowsatin
在
didSelectRow…
方法中,需要更新一个标志(存储在实例变量中),指示单元格的新“模式”。然后通过调用tableView reloadrowsatindexpath:withRowAnimation:
传递选定的indexPath来重新加载行
在您的
cellForRow…
方法中,使用标志确定两种类型的单元格中的哪一种用于该行。是否有特定的代码块给您带来麻烦?我不知道你在问什么,也不知道链接的相关性。你可以通过一个实例变量来实现这一点,该变量保存当前选定的索引。然后重新加载tableview。In-CellForRowatineXpath:您可以检查indexPath是否等于selectedIndexPath,然后初始化第二个自定义单元格。这正是我试图解决的问题,但我无法将新nib加载到旧单元格中。您是否有任何可以发布的代码示例?@NSNolan链接的相关性是《表视图编程指南》。这是一个非常开放的问题。您应该了解您已经尝试过的内容,并指出您正在遇到的特定问题以及相关代码。请看这个:
#pragma mark - UITableView delegate methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.array count];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == [self currentCellIndex]) {
[self setCurrentCellIndex:-1];
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"NewCell" owner:self options:nil];
OldCell *cell = (OldCell *)[tableView cellForRowAtIndexPath:indexPath];
cell = [nibs objectAtIndex:0];
}
else {
[self setCurrentCellIndex:indexPath.row];
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"NewCell" owner:self options:nil];
NewCell *cell = (NewCell *)[tableView cellForRowAtIndexPath:indexPath];
cell = [nibs objectAtIndex:0];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"OldCell";
OldCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"OldCell" owner:self options:nil];
cell = [nibs objectAtIndex:0];
}
return cell;
}