【发布时间】:2012-01-12 14:39:58
【问题描述】:
我有一个包含许多单元格的表格视图。每个单元格都有自己的 UITextField。我以编程方式添加了文本字段。我希望每个 textField 在按下编辑按钮时出现。 (现在表格处于编辑模式),当再次按下时,我希望所有的文本字段都消失(离开编辑模式)。我知道我可以使用 hidden 属性来完成此操作,但我尝试在此方法中执行此操作:
- (IBAction)editButton:(id)sender
{
if (self.editing)
{
[self setEditing:NO animated:YES];
[self.myTableView setEditing:NO animated:YES];
EditButton.title = @"Edit";
cellText.hidden = YES; //<-- THIS IS THE CODE
}
else
{
[self setEditing:YES animated:YES];
[self.myTableView setEditing:YES animated:YES];
EditButton.title = @"Done";
cellText.hidden = NO; //<-- THIS IS THE CODE
}
}
但它只显示和隐藏最后一个单元格的文本字段。我怎样才能让它显示在哪里,然后不显示每个单元格的文本字段?非常感谢提前!!!
行单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cellText = [[UITextField alloc]init];
[cellText setFrame:CGRectMake(190, 15, 55, 30)];
cellText.text = @"1";
cellText.borderStyle = UITextBorderStyleRoundedRect;
cellText.hidden = YES;
cellText.userInteractionEnabled = NO;
[cell addSubview:cellText];
}
return cell;
}
提前致谢!! :D
【问题讨论】:
-
您在使用 cellForRowAtIndexPath 方法的代码中犯了一些错误。请确保传递每个 textField 的标签。请发布该方法的一些代码。这将真正帮助我们解决问题。
-
好吧!我现在会!感谢您的帮助!
标签: iphone ios uitableview