我正在嘗試向表格視圖中的每個單元格添加一個自定義單選按鈕。當我第一次查看錶格視圖時,我看不到任何單選按鈕。但是當我向下滾動時,可以看到當視圖第一次加載時看到的初始單元格下方的每個單元格上的單選按鈕。而一旦沒有單選按鈕的單元出現在視圖中,我又回過頭去查看那個單元,就會出現單選按鈕。我向下滾動頁面一次後會出現表視圖按鈕
這裏是我的這一個方法的代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *ImageCellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ImageCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ImageCellIdentifier];
cell.accessoryType = UITableViewCellAccessoryNone;
}
_radioBtn.frame = CGRectMake(275, 3,36,36);
_radioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_radioBtn setImage:[UIImage imageNamed:@"Radio-Btn.png"] forState:UIControlStateNormal];
[cell.contentView addSubview:_radioBtn];
NSString *cellValue = [_arrayRelat objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
cell.textLabel.textColor = [UIColor colorWithRed:(88.0/255.0) green:(88.0/255.0) blue:(89.0/255.0) alpha:1];
return cell;
}
讓我知道,如果你不明白的問題。
什麼是_radioBtn? – Bot
我不明白,你如何得到一個沒有單選按鈕的單元格!您正在向所有單元格添加單選按鈕。沒有條件添加單選按鈕。 –