How to make tableviewcell text editable on touch in iPhone SDK?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 06:49:33

问题


In my iPhone app, I have a table view.

I want that when the user selects (or basically touches) on the cell of the tableview then he/she should be able to edit the cell contents.

How can I do that?


回答1:


@PARTH in order to make your UITableView cells editable i suggest u to give textfields to your cell....

eg:- In

-(UITableViewCell *)reuseTableViewCellWithIdentifier:(NSString *)identifier withIndexPath:(NSIndexPath *)indexPath {


    CGRect cellRectangle = CGRectMake (0, 10, 300, 70); 
    CGRect Field1Frame = CGRectMake (10, 10, 290, 70);
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:cellRectangle reuseIdentifier:identifier] autorelease];
    UITextField *textField;


    //Initialize Label with tag 1.

    textField = [[UITextField alloc] initWithFrame:Field1Frame];

    textField.tag = 1;
    [cell.contentView addSubview:textField];

[textField release];
    return cell;
}

and in your cellForRowAtIndexPath method // Configure the cell.

 UITextField *txtTemp = (UITextField *)[cell.contentView viewWithTag:1];

use this where u want in your tableview accordingly otherwise hide it.....Hope it will help u!!




回答2:


you need to put text field inside the table cell use this link.



来源:https://stackoverflow.com/questions/4677532/how-to-make-tableviewcell-text-editable-on-touch-in-iphone-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!