[英]How to make the user select only one custom UIButton in a view with multiple UIButtons? Swift 3
[英]clicking on one uibutton in custom uitableviewcell selects multiple uibuttons in uitableview
我在uiviewcontroller的childViewController中有一個uitableview。 在該uitableview中,我使用了自定義uitableviewcell。 在該自定義uitableviewcell中,我有“收藏夾”復選框按鈕。
該uitable視圖包含大約30條記錄,大約10條記錄出現在可見屏幕上,然后滾動顯示另外10條,然后滾動另一條。
問題是當我在第一行選擇一個uibutton,然后向下滾動uitableview時,我也看到它在第11和21行也被選中。 我已經忙了半天了,但是找不到問題。 請幫忙。
這是cellForRowAtIndexPath
代碼:
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ABCViewCell *cell = (ABCViewCell*)[tableView dequeueReusableCellWithIdentifier:@"ABCViewCell" forIndexPath:indexPath];
cell.delegate = self;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.layoutMargins = UIEdgeInsetsZero;
cell.labelDesiredDate.text = [dateFormatter stringFromDate:[NSDate date]];
cell.labelJournaledDate.text = [dateFormatter stringFromDate:[NSDate date]];
return cell; }
謝謝阿卜杜勒
您必須記住,當您使用dequeueReusableCellWithIdentifier
方法時,您的單元格將成為繪制所有內容的開始記錄。 因此,您必須考慮一種清除數據的方法。
如下所示:
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ABCViewCell *cell = (ABCViewCell*)[tableView dequeueReusableCellWithIdentifier:@"ABCViewCell" forIndexPath:indexPath];
if ([self shouldMyCellBeSelected]) {
[cell displayButtonSelected];
} else {
[cell displayButtonUnselected];
}
return cell;
}
希望能有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.