【发布时间】:2013-02-26 11:03:14
【问题描述】:
我的代码中有一个简单的关键问题。
当我按下我的编辑按钮(在导航栏上)时,在我的 Tableview 上它需要我编辑 UITableview 的方法。我想隐藏 My Cell 上的按钮和标签。
代码:
我正在像这样添加我的按钮..
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *currentCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
currentCell = nil;
if (currentCell==nil)
{
currentCell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
BtnEmail=[UIButton buttonWithType:UIButtonTypeCustom];
//BtnEmail = (UIButton *)[currentCell viewWithTag: 3];
BtnEmail.frame=CGRectMake(265, 17, 25, 25);
BtnEmail.tag=indexPath.row;
//[BtnEmail setTitle:@"E-mail" forState:UIControlStateNormal];
[BtnEmail setBackgroundImage:[UIImage imageNamed:@"email.png"] forState:UIControlStateNormal];
[BtnEmail addTarget:self action:@selector(BtnEmail:) forControlEvents:UIControlEventTouchUpInside];
[currentCell.contentView addSubview:BtnEmail];
[currentCell.contentView bringSubviewToFront:BtnEmail];
return currentCell;
}
我的编辑按钮是这样声明的
编辑按钮:
self.navigationItem.rightBarButtonItem = self.editButtonItem;
并且在编辑时单击我的这个方法将调用 .
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[listTableView setEditing:editing animated:animated];
if(editing)
{
self.navigationItem.leftBarButtonItem.enabled = NO;
//BtnEmail.frame=CGRectMake(355, 17, 25, 25);
BtnEmail.hidden = TRUE;
}
else
{
self.navigationItem.leftBarButtonItem.enabled = YES;
//BtnEmail.frame=CGRectMake(265, 17, 25, 25);
BtnEmail.hidden = FALSE;
}
[super setEditing:editing animated:animated];
}
在这种情况下,我的 Last cell Button 和 Lable 不会全部隐藏。我需要隐藏 Cell 的所有 UIButton 。
如果 我在桌子上有 3 个单元格,那么它只会隐藏最后一个按钮 ..
谢谢。
【问题讨论】:
-
这将是因为在这种情况下,您将获得最后创建的 BtnEmail 引用。
标签: iphone ios uitableview show-hide