當我的滾動視圖更寬時,我的單元格按鈕顯示出來了。我把它做得更小,我的按鈕也消失了。我已經玩過這個框架,但它似乎不工作。有什麼建議麼?UITableView -cell按鈕沒有顯示出來
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
UIButton*button= [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(10.0, 0.0, 20,20);
[button setTitle:@"Tap" forState:UIControlStateNormal];
button.backgroundColor= [UIColor blackColor];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = button;
[cell.contentView addSubview:button];
}
NSString *cellValue = [selection objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
是否曾經調用過cell == nil分支?或者以不同的方式提問:您是否註冊了重用Idenitfier Cell的UITableViewCell類?或者你在使用故事板? –
不使用筆尖。不知道您的註冊問題是什麼意思,但if語句被稱爲 –
爲什麼您將此按鈕分配給附件視圖?據我的理解,這將使表使用按鈕,儘管它已經是一個子視圖,並將其作爲子視圖添加到附件視圖應該在的框架中。這可能就在可見框架之外。通過這樣做,作爲子視圖的現有關聯被刪除,因爲每個視圖在子視圖層次結構中一次只能一次。它也可能改變框架。您是否在調試和addSubview語句後嘗試調試或nsloging按鈕框架? –