【发布时间】:2012-02-09 11:01:46
【问题描述】:
我是这个 iphone 开发的新手。 我只想知道如何在 tableView 中编辑/更新 UITextLabel。
我已经在使用编辑/完成动画并且能够删除行,但我不知道如何编辑这些行中的文本。
我希望用户在点击编辑按钮时编辑单元格的文本标签。
我已经搜索了该网站,但无法得到确切的答案。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
if(!cell)
{
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellIdentifier"]autorelease];
cell.editingAccessoryType=YES;
}
myTextField = [[UITextField alloc] initWithFrame:CGRectMake(15, 6, 241, 31)];
myTextField.backgroundColor = [UIColor clearColor];
myTextField.textAlignment = UITextAlignmentLeft;
myTextField.returnKeyType = UIReturnKeyDone;
myTextField.delegate = self;
cell.accessoryView = myTextField;
myTextField.text = [self.arrayOfItems objectAtIndex:indexPath.row];
myTextField.enabled = NO;
return cell;
}
-(IBAction)Edit:(id)sender
{
if(self.editing)
{
[myTextField.Enabled = YES];
[super setEditing:NO animated:NO];
[self.tab setEditing:NO animated:NO];
[self.tab reloadData];
[self.navigationItem.rightBarButtonItem setTitle:@"Done"];
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStylePlain];
}
else
{
myTextField.enabled= YES;
[super setEditing:YES animated:YES];
[self.tab setEditing:YES animated:YES];
[self.tab reloadData];
[self.navigationItem.rightBarButtonItem setTitle:@"Edit"];
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone];
}
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.editing == NO || !indexPath)
return UITableViewCellEditingStyleNone;
if (self.editing && indexPath.row == ([self.arrayOfItems count]))
{
return UITableViewCellEditingStyleInsert;
}
else
{
return UITableViewCellEditingStyleDelete;
}
return UITableViewCellEditingStyleNone;
}
这对我不起作用。如果我点击编辑按钮,文本字段就会消失
【问题讨论】:
标签: iphone ios uitableview