繁体   English   中英

如何直接在UITableView中编辑行,而无需进入编辑模式

[英]How to directly edit a row in a UITableView, without entering in Editing Mode

UITableView ,当触摸这样的行时,我希望能够编辑该行的cell.textLabel.text属性。

换句话说,我希望能够直接触摸该行来对其进行编辑,而不是进入编辑模式。

我该如何实施?

- (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;
}

这是CMTableViewCell的子类:

...

-(void)viewDidLoad
{    
    textField = [[UITextField alloc] init];
    [textField setFrame:CGRectMake(5,5,50,400)];
    [self addSubview:textField];
}

添加不带边框的UITextField作为子视图。 在将其添加到子视图之前-在tableview cellForRowAtIndexPath方法的indexPath.row中将Tag indexPath.row设置为UITextField 用户输入数据时-按下“返回”按钮时,使用UITextFieldDelegate方法保存数据。 不幸的是我不能给你代码,因为现在我在Windows上。 首页这将有所帮助

更新 :更改数据源中的数据所需的标记号。 当您在UITextField中按下“返回”按钮时,可以通过从UITextField中使用此标记号获取UITableViewCell来保存更改。

这很简单:

- (void)tableView:(UITableView *)tableView
                             didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.textLabel.text = @"...";
}

更新

- (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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM