Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

iphone - In-place editing of text in UITableViewCell?

I know this has to be a really simple question, but I am having trouble finding it in a simple place where there aren't so many other things going on that I can isolate the specific behavior.

I know I need to add a UITextField as a subview to the UITableViewCell to make it editable. What is the best way to do this? (I see an example in UICatalog, but I am confused with all of the extra things it is doing with the Dictionary.)

Again, please excuse the ignorance of this question. A pointer to sample code or a screencast would be much appreciated.

Thanks in advance,

Alan

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First, define about UITextField.

txtField=[[UITextField alloc]initWithFrame:CGRectMake(5, 5, 320, 39)];
txtField.autoresizingMask=UIViewAutoresizingFlexibleHeight;
txtField.autoresizesSubviews=YES;
txtField.layer.cornerRadius=10.0;
[txtField setBorderStyle:UITextBorderStyleRoundedRect];
[txtField setPlaceholder:@"Type Data Here"];

Then write the code below in cellForRowAtIndexPath method

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     static NSString *CellIdentifier = @"CellIdentifier";
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil)
   {
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
      cell.accessoryType = UITableViewCellAccessoryNone;
    }
    [cell addSubview:txtField];
    return cell;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...