2015-11-20 63 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); 
    } 
} 
相关问题