Я добавил три UIButtons
к каждой строке UITableViewCell
.Обновление содержимого UITableviewcell
Когда я выбираю UIButton
, он меняет цвет на черный. Проблема заключалась в том, что изменения цвета были затронуты кнопками другой ячейки в таблице, которую я только видел, когда прокручиваю вниз по таблице.
ссылку также объяснить тот же проблемно>UITableviewcell content updating reflects to other cell
я не мог найти ответ на эту проблему в IOS.
это мой cellForRowAtIndexPath
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"custCell"];
UIButton *btn1=[cell viewWithTag:101];
btn1.imageView.contentMode = UIViewContentModeScaleAspectFit;
[btn1 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn1.backgroundColor=[UIColor clearColor];
[btn1 setTag:(indexPath.row*3)+1];
UIButton *btn2=[cell viewWithTag:102];
btn2.imageView.contentMode = UIViewContentModeScaleAspectFit;
[btn2 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn2.backgroundColor=[UIColor clearColor];
[btn2 setTag:(indexPath.row*3)+2];
UIButton *btn3=[cell viewWithTag:103];
btn3.imageView.contentMode = UIViewContentModeScaleAspectFit;
[btn3 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn3.backgroundColor=[UIColor clearColor];
[btn3 setTag:(indexPath.row*3)+3];
rerutn cell;
это я моя кнопка метод действия
- (IBAction)btnClicked:(id)sender
{
UIButton *button=(UIButton *)sender;
NSLog(@"tag %ld",(long)button.tag);
if(button.backgroundColor==[UIColor blackColor]){
button.backgroundColor=[UIColor clearColor];
}
else if(button.backgroundColor==[UIColor clearColor]){
button.backgroundColor=[UIColor blackColor];
}
}
Nothin фантазии в этом коде. Как я могу решить эту проблему программно .. Спасибо ..!
Возможный дубликат [UITableViewCell обновления контента отражает в другой ячейке] (http://stackoverflow.com/questions/14278144/uitableviewcell-content-updating-reflects-to-other-cell) – Avi
Да. У вас есть какие-то решения ??? – gamal
Используйте то же самое в cellforrowatindex, которое вы сделали в IBAction –