我選擇在我UITableViewCell
一個UIButton
和保持它選擇的Ive加入一個圖像每UIButton
的每個狀態(通過Interface Builder
,不編程)。但是當我滾動時,選中的狀態顯示爲重複。我讀了很多類似的信息,但無法找到解決我的問題的帖子。我注意到tableView
正在重複使用緩存中的單元格,其狀態爲UIButton
。重複的的UIButton的選擇狀態中的UITableViewCell插入時滾動的UITableView
這是我的代碼。
以我Custom Cell
:
- (IBAction)highlightStar:(UIButton *)sender {
self.starButton.selected=!sender.selected;
}
以我控制器viewDidLoad
:
UINib *nib = [UINib nibWithNibName:@"CellS"
bundle:nil];
[self.tableView registerNib:nib
forCellReuseIdentifier:CellIdentifier];
以我控制器cellForRowAtIndexPath
:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CellS *cell = (CellS *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.backgroundColor = [UIColor clearColor];
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
NSDictionary *dict=self.items[indexPath.row];
NSString *header=[dict objectForKey:@"header"];
[cell.labelReader setText:header];
return cell;
}
捕捉1(不滾動)。選擇的兩個UIButtons:
捕獲2(與滾動)。選擇了兩個重複的UIButton:
感謝
謝謝!我正在努力, – santibernaldo