如何在不创建引用出口的情况下访问静态 TableViewcells 中的文本字段? [英] How Can I access the textfields in static TableViewcells without creating referencing outlet?
本文介绍了如何在不创建引用出口的情况下访问静态 TableViewcells 中的文本字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有很多文本字段静态放置在静态 TableViewcells 中.如何在不为每个文本字段创建引用出口的情况下访问其中的文本?我试过对单元格进行子视图.它不起作用.有其他选择吗?
I have lot of text fields statically placed in static TableViewcells. How can access the text in it without creating referencing outlet for each textfield? I have tried taking subviews of cell. It's not working. Any alternatives?
我试过了.它不起作用.
I tried this. It's not working.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [super tableView:tableView
cellForRowAtIndexPath:indexPath];
for (UIView *subview in [cell subviews]){
if([subview isKindOfClass:[UITextField class]]){
UITextField *inputField = (UITextField *)subview;
NSLog(@"%@",inputField.text);
}
}
return cell;
}
推荐答案
您可以使用 IBOutletCollection.这让您可以将它们全部连接到一个数组,您可以在其中通过索引访问它们,或者使用 setValue:forKey: 一次性处理它们.
You could use an IBOutletCollection. That lets you connect them all to one array, where you can access them by index, or use setValue:forKey: to address them all at once.
这篇关于如何在不创建引用出口的情况下访问静态 TableViewcells 中的文本字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文