質問自体を投稿する前に、これが脱獄アプリであることを述べる必要があります。これが、ファイルシステムの「奇妙な」フォルダーに書き込んでいる理由です。
続けましょう。
これが私の 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 というメンバーを使用して、現在「選択」されているセルをポイントします。これはオプション テーブルであり、ユーザーはいつでもチェックマーク アクセサリ アイコンが付いたセルを 1 つだけ持つことができます。
ユーザーが別のセルを選択すると、オプションが変更され、チェックマークが現在のセルから消えて、新しく表示されたセルに表示されるはずです。私はこのようにします:
-(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で取得したセルからアクセサリタイプを変更しようとすると、何らかの理由でまったく機能しないようです。
どんな助けでも大歓迎です。