2012-06-07 48 views

回答

3

在textfieldDidEditing,就可以得到相應的文本框的單元格,計算值,並將其分配給標籤如下:

yourTableViewCell *cell = (yourTableViewCell *)[[textField superview] superview]; 
cell.yourLabel.text = value; 
+0

我有一個單元格,其中我有subview標籤,我無法調用cell.labelname.text – Purva

+0

無論是什麼層次結構,如果它是您的單元格的子視圖,您可以從您的文本字段中獲取單元格。您可以使用上面的方法(superview)來獲取單元格,你只需要確定你的視圖的層次結構。 –

0
/* u just give Tag to TextField and in textFieldDidEndEditing, save textfield text into an string and then reload the row...here is the code..also have sample */ 


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexpath 
{ 
    UITableViewCell *cell = [[UITableViewCell alloc] init]; 

    UITextField *txtField1 = [[UITextField alloc]initWithFrame:CGRectMake(20, 10, 100, 80)]; 
    txtField1.tag = indexpath.row; 
    txtField1.delegate= self; 
    [cell addSubview:txtField1]; 

    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(140, 10, 100, 80)]; 

    [cell addSubview:label1]; 

    //set text in label ** str1 comes from textFieldDidEndEditing 
    label1.text = str1; 

    return cell; 
} 

-(void)textFieldDidEndEditing:(UITextField *)textField 
{ 
    //save textField text to any string**declair it global 
    str1 = textField.text; 

    //reload selected row in table 
    NSIndexPath *durPath = [NSIndexPath indexPathForRow:textField.tag inSection:0]; 
    NSArray *paths = [NSArray arrayWithObject:durPath]; 
    [tbl reloadRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationRight]; 
} 
相關問題