在我发布问题本身之前,我需要说明这是一个越狱应用程序。这就是为什么我在文件系统中的“奇异”文件夹中写入内容。
让我们继续。
这是我的 cellForRowAtIndexPath 方法:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"pluginCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
if(indexPath.row == 0)
{
cell.textLabel.text = @"default";
}else
{
//Get the plugin's display name.
NSBundle *currentPlugin = [[NSBundle alloc] initWithPath:[NSString stringWithFormat:@"/Library/Cydeswitch/plugins/%@", [plugins objectAtIndex:indexPath.row - 1], nil]];
cell.textLabel.text = [[currentPlugin localizedInfoDictionary] objectForKey:@"CFBundleDisplayName"];
if(cell.textLabel.text == nil)
{
//No localized bundle, so let's get the global display name...
cell.textLabel.text = [[currentPlugin infoDictionary] objectForKey:@"CFBundleDisplayName"];
}
[currentPlugin release];
}
if([[[cell textLabel] text] isEqualToString:[settings objectForKey:@"pluginToExecute"]])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
currentCell = [cell retain];
}
return cell;
}
如您所见,此方法使用一个名为 currentCell 的成员来指向当前“选定”的单元格。这是一个选项表,用户在任何时候都应该只能有一个带有复选标记附件图标的单元格。
当用户选择另一个单元格时,他正在更改一个选项,并且复选标记应该从当前单元格中消失并出现在新出现的单元格中。我这样做:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
currentCell.accessoryType = UITableViewCellAccessoryNone;
[currentCell release];
currentCell = [[self tableView:tableView cellForRowAtIndexPath:indexPath] retain];
NSLog(@"CURRENT CELL %@", currentCell.textLabel.text);
currentCell.accessoryType = UITableViewCellAccessoryCheckmark;
}
但它不起作用。当我点击另一个单元格时,复选标记正确地从旧单元格中消失,但它从未出现在新单元格中。
我知道选择工作正常,因为那里的 NSLog 可以很好地打印新单元格的文本。
我之前尝试过跟踪 indexPath,但它根本不起作用。当我尝试使用 indexPaths 而不是指向单元格的指针时,当用户点击单元格时,什么都没有发生(至少在我目前的方法中,复选标记从旧单元格中消失了)。
我认为这与 cellForRowAtIndexPath 有关,因为如果我一直指向单元格,复选标记就会消失,但是由于某种原因,当尝试从使用 cellForRowAtIndexPath 获取的单元格中更改附件类型时,它似乎根本不起作用。
任何帮助将不胜感激。