[英]How to directly edit a row in a UITableView, without entering in Editing Mode
In a UITableView
, I would like to be able to edit the cell.textLabel.text
property of the row, when such row is touched. 在
UITableView
,当触摸这样的行时,我希望能够编辑该行的cell.textLabel.text
属性。
In other terms, I would like to be able to edit the row directly touching it, instead of entering into edit mode. 换句话说,我希望能够直接触摸该行来对其进行编辑,而不是进入编辑模式。
How can I implement this? 我该如何实施?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CMTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CMTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
int tagsCount = [[currentComic Tags] count];
[[cell textField] setTag:[indexPath row]];
[[cell textField] setText:[tagsDisplayName objectAtIndex:[indexPath row]]];
return cell;
}
And this is the subclass CMTableViewCell: 这是CMTableViewCell的子类:
...
-(void)viewDidLoad
{
textField = [[UITextField alloc] init];
[textField setFrame:CGRectMake(5,5,50,400)];
[self addSubview:textField];
}
Add UITextField
without borders as subview. 添加不带边框的
UITextField
作为子视图。 Before adding it to subview - set Tag nubmer to UITextField
from indexPath.row
at tableview cellForRowAtIndexPath
method. 在将其添加到子视图之前-在
tableview cellForRowAtIndexPath
方法的indexPath.row
中将Tag indexPath.row
设置为UITextField
。 When user entered data - save it with UITextFieldDelegate
methods when "Return" button was pressed. 用户输入数据时-按下“返回”按钮时,使用
UITextFieldDelegate
方法保存数据。 Unfortunately I can't give you code, because right now I'm on Windows. 不幸的是我不能给你代码,因为现在我在Windows上。 Home this will help
首页这将有所帮助
UPDATE : Tag number needed to change data in your DataSource. 更新 :更改数据源中的数据所需的标记号。 When you pressed "Return" button in your UITextField, you can save changed by getting UITableViewCell by this tag number from UITextField.
当您在UITextField中按下“返回”按钮时,可以通过从UITextField中使用此标记号获取UITableViewCell来保存更改。
It's simple: 这很简单:
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.text = @"...";
}
UPDATE 更新
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITextField *textField = [[UITextField alloc] init];
[textField setTag:[indexPath row]];
[tagsTableView addSubview:textField];
FreeAndNil(textField);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.