【发布时间】:2011-02-12 03:28:58
【问题描述】:
通常我有标签和一些文本字段,它们是 IBOutlets,如果有人单击按钮,我可以轻松读取这些文本字段的文本值
self.myTextfield1.text;
但现在我有一个带有自定义表格单元格的UITableView。在这些单元格中,我有一个标签和一个文本字段。加载时,我在cellForRowAtIndexPath 中执行此操作:
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyCell *cell = (MyCell*)[theTableView dequeueReusableCellWithIdentifier:@"MyCell"];
if (!cell) {
[[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil];
cell = self.myCell;
self.myCell = nil;
}
switch (indexPath.section) {
case 0:
switch (indexPath.row) {
case 0:
cell.myCellLabel.text = @"Label1";
cell.myCellTextField.text = @"...";
break;
case 1:
cell.myCellLabel.text = @"Label2";
cell.myCellTextField.text = @"...";
break;
// and so on...
default:
break;
}
break;
case 1:
switch (indexPath.row) {
case 0:
cell.myCellLabel.text = @"Label1_1";
cell.myCellTextField.text = @"...";
break;
// and so on...
}
default:
break;
}
return cell;
}
因此,如果有人单击该按钮,我将无法访问带有self.mytextfield1.text 的字段的文本值。如何获取字段的值?我知道标签的值应该在哪个部分和哪一行。因此,如果我可以结合节和行号获得文本字段的值,那就太好了。
也许有人知道如何解决这个问题?
最好的问候,蒂姆。
【问题讨论】:
标签: iphone objective-c