Я все еще в процессе ознакомления с iPhone SDK.Выбор UITableViewCell остается во всех ячейках!
Это то, что я пытаюсь сделать:
У меня есть UIScrollView, и каждый вид прокрутки имеет UITableView и я реализовал обычай UITableViewCell.
Желаемая функциональность изначально отсутствует, тогда пользователь выбирает строку и прокручивает и делает другой выбор в следующем прокрутке и продолжает. Я хочу, чтобы выбор оставался, поэтому пользователь может изменить выбор в более поздней точке.
Однако, что происходит в моем случае - первый и второй UITableViews прекрасны, выбранная строка остается выбранной, но в третьем UITableView я вижу выбранную строку «уже», которая аналогична первой UITableView. Я не хочу видеть выбранных.
Я знаю, что делаю что-то глупое, но не могу понять, что. Любая помощь могла бы быть полезна.
Спасибо, Эми
Вот соответствующие методы источника данных и делегат.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%s", __FUNCTION__);
static NSString * ChoiceTableCellIdentifier = @"ChoiceTableCellIdentifier";
choiceTableCell = (ChoiceTableCell *)[tableView dequeueReusableCellWithIdentifier:ChoiceTableCellIdentifier];
if(choiceTableCell == nil)
{
choiceTableCell = [[[ChoiceTableCell alloc]
initWithFrame:CGRectZero
reuseIdentifier:ChoiceTableCellIdentifier] autorelease];
}
return choiceTableCell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%s", __FUNCTION__);
int newRow = [indexPath row];
int oldRow = [lastIndexPath row];
if ((newRow != oldRow) || (newRow == 0))
{
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
UIImageView *indicatorN = (UIImageView *)[newCell.contentView viewWithTag:SELECTION_INDICATOR_TAG_1];
indicatorN.image = [UIImage imageNamed:@"selected.png"];
newCell.backgroundView.backgroundColor = [UIColor clearColor];
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];
UIImageView *indicatorO = (UIImageView *)[oldCell.contentView viewWithTag:SELECTION_INDICATOR_TAG_1];
indicatorO.image = [UIImage imageNamed:@"notSelected.png"];
oldCell.backgroundView.backgroundColor = [UIColor clearColor];
lastIndexPath = indexPath;
}
}