2012-01-10 94 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];添加單元格。後來隨着標籤的幫助下訪問它。