我正在使用带有文本字段的自定义UITableViewCell
。当我按下右侧导航栏按钮(例如:完成等)时,我想访问每个文本字段的数据。我使用以下代码:
- (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 :(得分: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
}
}
答案 1 :(得分: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);
}
}