질문을 게시하기 전에 본인은 본때를 보여주는 앱임을 명시해야합니다. 이것이 필자가 파일 시스템의 "기괴한"폴더에 쓰는 이유입니다.didSelectRowAtIndexPath에서 액세서리 유형을 변경할 수 없습니까?
계속하겠습니다. 당신이 볼 수처럼
-(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라는 멤버를 사용
여기 내 cellForRowAtIndexPath 방법입니다. 이것은 옵션 테이블이며 사용자는 언제든지 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로 가져온 셀에서 액세서리 유형을 변경하려고 할 때 어떤 이유로 작동하지 않는 것 같다. 모든.
도움이 될 것입니다.
네,이 솔루션은 하하 위의 대답과 함께 작동합니다. 잡종 대답. –