我目前正在尝试使用户能够编辑多个单元格的内容。更新后,数据将发送到Web服务。
现在,据我所知,只有“删除”和“添加”行。我似乎找不到任何有关如何编辑单元格内容的指南或教程。
非常感谢您的建议和/或建议。
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
您不能直接编辑单元格内容。如果您需要编辑内容,则在单元格中添加UITextField
或UITextView
作为其子视图。然后访问它们。
编辑:您可以添加文本字段,如下所示:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"cellIdentifier";
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
// ADD YOUR TEXTFIELD HERE
UITextField *yourTf = [[UITextField alloc] initWithFrame:CGRectMake(0, 5, 330.0f, 30)];
[yourTf setBackgroundColor:[UIColor clearColor]];
yourTf.tag = 1;
yourTf.font = [UIFont fontWithName:@"Helvetica" size:15];
yourTf.textColor = [UIColor colorWithRed:61.0f/255.0f green:61.0f/255.0f blue:61.0f/255.0f alpha:1.0f];
yourTf.delegate = self;
[cell addSubview:yourTf];
}
// ACCESS YOUR TEXTFIELD BY REUSING IT
[(UITextField *)[cell viewWithTag:1] setText:@"YOUR TEXT"];
return cell;
}
实现UITextField委托,然后您可以使用此UITextField编辑单元格内容。
希望对您有帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句