2012-01-10 93 views
0

我想给在tableviewcell文本框我writen一些代码,我可以看到细胞文本框,但是当我去下一个单元格,然后我的价值是即消失,以及如何给细胞键盘即消失,请检查这个代码,我对细胞writen,请帮我如何从细胞即消失键盘。如何给细胞文本框在iphone

我想给文本框不仅在一排在所有行。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    if ([indexPath row] == 0 && [indexPath section] == 0) 
    { 
    [email protected]"Tags"; 
     UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 185, 30)]; 
     cell.accessoryView = textField; 

    } 

    if ([indexPath row] == 1 && [indexPath section] == 0) 
    { 
     [email protected]"Notes"; 
     cell.detailTextLabel.text=app.Notes; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 
} 

回答

0

要关闭键盘类应符合UITextFieldDelegate协议 ,你应该实现此方法:当你的UITableView决定重新查询你的

- (BOOL)textFieldShouldReturn:(UITextField *)txtField { 
    [txtField resignFirstResponder]; 
    return YES; 
} 
0

你的价值消失。

看看你现在在做什么:你创建一个新的单元格,它带有一个新的UITextField,因为它是新的 - 不包含任何值。那么你的旧单元(和它的价值)就会丢失。

0

隐藏键盘“铍” &“斯塔斯”是正确的。为了保持该文本框的文本,存储文本中textFieldDidEndEditing方法,像这样:

- (void)textFieldDidEndEditing:(UITextField *)textField 
{ 
    nameString = textField.text; 
} 

在你cellForRowAtIndexPath方法设置文本框的文本textField.text = nameString初始化文本框后。

0

你可以做一件事也是这个集标签。并将其添加到单元格直接没有accessoryView。使用[cell addSubview:textField];添加单元格。后来随着标签的帮助下访问它。