2015-11-20 98 views
0

我正在使用帶有文本字段的自定義UITableViewCell。我想在按下右側導航欄按鈕時訪問每個文本框的數據(例如:完成等)。我使用下面的代碼:自定義UITableViewCell與UITextfield使用Xcode 7

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    return 2; 
} 

#pragma mark - UITableViewDelegate 

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

    CustomCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil] objectAtIndex:0]; 
    if (cell == nil) { 

    } 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    cell.valueTextField.delegate = self; 
    switch (indexPath.row) { 
     case 0: 
      cell.itemImageView.image = [UIImage imageNamed:@"user.png"]; 
      cell.valueTextField.placeholder = @"UserName"; 
      break; 
     case 1: 
      cell.itemImageView.image = [UIImage imageNamed:@"mail.png"]; 
      cell.valueTextField.placeholder = @"Email"; 

     default: 
      break; 
    } 

回答

0

試試這個

-(IBAction)rightNavigationButton:(id)sender 
{ 

NSInteger rowNumber = [projectListTable numberOfRowsInSection:0]; 

    NSIndexPath *indexpath = [NSIndexPath indexPathForRow:[projectListTable numberOfRowsInSection:0] inSection:0]; 

    for(int i = 0; i < rowNumber; i++) 
    { 
     CustomCell *cell = [projectListTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:rowNumber inSection:0]]; 
     NSString *str = cell.valueTextField.text; 

//Do here what you want to do with textfield of each cell 
    } 
} 
+0

其不工作iOS9 – IKKA

+0

是Xcode中拋出的任何錯誤? –

0

我解決了這樣的問題:

-(void)clickOnSend:(id)sender{ 

    NSInteger dynamicRows = [self.createUserTableView numberOfRowsInSection:0]; 
    for (int i=0; i<dynamicRows; i++) { 
     NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0]; 
     UserProfileCell *cell = (UserProfileCell *)[self.createUserTableView cellForRowAtIndexPath:indexPath]; 
     DLog(@"cell textfield string :%@",cell.valueTextField.text); 
    } 
} 
相關問題