有一次,当我的滚动视图更宽时,我的单元格按钮出现了。我把它变小了,我的按钮消失了。我玩过框架,但它似乎不起作用。有什么建议么?
- (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;