我在 xcode 4.6 中创建了主详细信息模板项目,并添加了带有 2 个文本字段的自定义单元格。我还创建了新类,它是 UITableViewCell 的子类,在这个类中我创建了文本字段的出口。当用户键入某些内容时, NSMutableArray 就会更新,并且效果很好。现在我想知道如何将此数组传递回 MasterViewController (UITableViewController),以便我可以使用此数据来显示计算。
我尝试使用 UIViewController 之间的委托教程,但我不断收到错误。任何帮助表示赞赏。
你不应该将数据保存在UITableViewCell
,因为它破坏了 MVC。
您需要获得以下参考UITextField
在你的手机上。这就是我在登录表单中的做法:
我有一个名为的自定义单元子类TextFieldCell
,它有一个名为textField
,我想要我的UITableViewController
有参考这些UITextField
s.
首先,我打开故事板,将单元格类设置为 TextFieldCell,然后将 UITextField 连接到单元格文本字段出口。比我把这个添加到tableView:cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
(…)
if (indexPath.row == 0) {
// Sets the textField of the first cell as the loginTextField.
self.loginTextField = tCell.textField;
} else {
// Sets the textField of the second cell as the passwordTextField.
self.passwordTextField = tCell.textField;
}
tCell.textField.delegate = self;
(…)
}
现在我可以访问我的价值loginTextField
and my passwordTextField
。我这样做是在tableView:cellForRowAtIndexPath:
因为那时我正在创建要添加到表视图的单元格。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)