在我發佈問題本身之前,我需要說明這是一個越獄應用程序。這就是爲什麼我正在寫文件系統中的「奇怪」文件夾。不能從didSelectRowAtIndexPath更改附件類型?
讓我們繼續。
這裏是我的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成員,使其指向當前「選擇」單元格。這是一個選項表,用戶應該只能隨時在Checkmark附件圖標上顯示一個單元格。
當使用情況選擇另一個單元格時,他正在更改選項,並且複選標記應該從當前單元格中消失並出現在新出現的單元格中。我這樣做:
-(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;
}
但它不起作用。當我點擊另一個單元格時,Checkmark正確地從舊單元格消失,但它從不出現在新單元格中。
我知道選擇工作正常,因爲NSLog在那裏打印新單元格的文本就好了。
我已經嘗試過跟蹤indexPath,但它根本不起作用。當我嘗試使用indexPaths而不是指向單元格的指針時,當用戶點擊單元格時根本沒有發生任何事情(至少在我目前的方法中,複選標記從舊單元格中消失)。
我認爲它與cellForRowAtIndexPath有關,因爲如果我一直指向單元格,複選標記會消失,但由於某種原因,當嘗試更改從cellForRowAtIndexPath獲取的單元格中的附件類型時,它似乎不起作用所有。
任何幫助將不勝感激。
是的,這個解決方案與上面的答案一起工作,哈哈。混合的答案。 – 2013-05-08 15:10:50