【发布时间】:2013-12-25 11:41:23
【问题描述】:
以编程方式创建了一个 UITableView,我在 iPad 主视图控制器中的 tableview 中的数据是动态加载的,我在最后一个单元格中放置了一个按钮,但该按钮再次出现在单元格下方的 tableview 中...第一次代码执行后,按钮只出现一次,但下一次出现两次...这是代码...
- (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];
}
if([_objects count] > 1)
{
if(indexPath.row == [_objects count])
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//set the position of the button
button.frame = CGRectMake(cell.frame.origin.x + 50, cell.frame.origin.y + 15, 225, 30);
[button setTitle:@"Hide me" forState:UIControlStateNormal];
[button addTarget:self action:@selector(customActionPressed) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor= [UIColor clearColor];
[cell.contentView addSubview:button];
}
else
{
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.textLabel.textColor = [UIColor colorWithRed:0/255.0 green:100.0/255.0 blue:220.0/255.0 alpha:1.0];
cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:13];
cell.textLabel.text = [_objects objectAtIndex:indexPath.row];
NSLog(@"%@", [_objects objectAtIndex:indexPath.row]);
}
}
return cell;
}
for ex:: 这是 tableview 的快照(我怎么能把图像放在这里???)
- aaa
- bbb
- ccc
- ddd
- 哎呀
-
UI按钮
UIButton 再次出现在 tableview 中
这是图片链接http://s10.postimg.org/fwarb2661/i_OS_Simulator_Screen_shot_28_Dec_2013_10_57_32_A.png
任何帮助表示赞赏,在此先感谢..
【问题讨论】:
-
请在此处发布一些代码
-
谢谢,上面添加了一些代码
标签: iphone objective-c ipad uitableview ios6