[英]using viewForHeaderInSection method in iOS application
I have a grouped UITableView with multiple segments. 我有一个带有多个细分的分组的UITableView。 I would like to have a button below each segment in the footer that when pushed would take the user to a different view controller (with some options - the data-model to be loaded in the destination VC).
我想在页脚的每个段下面都有一个按钮,当按下该按钮时,会将用户带到另一个视图控制器(有一些选项-要在目标VC中加载的数据模型)。 The two ViewControllers in question are managed by a UINavigationController.
有问题的两个ViewController由UINavigationController管理。
I am not sure what the best way to achieve this is... 我不确定实现此目标的最佳方法是...
I have tried: 我努力了:
Creating each UIView (with the button) in IB and trying to add the view to a section footer there. 在IB中创建每个UIView(使用按钮),然后尝试将视图添加到此处的页脚。 I do not think this is possible.
我认为这是不可能的。
Creating the UIViews purely in code, add then adding them to each of the section footers. 纯粹用代码创建UIView,添加然后将它们添加到每个节的页脚中。 This is working fine however the issue here is that I then cannot wire in my segue & segue identifier in IB.
这很好用,但是这里的问题是我无法在IB中连接我的segue和segue标识符。 I am using the prepareForSegue method to send the correct data-model to the destination VC (depending on which segment footer button is pushed) so I require this.
我正在使用prepareForSegue方法将正确的数据模型发送到目标VC(取决于按下哪个段页脚按钮),因此我需要这样做。 Is there an alternative here, can I trigger send my data-model in some other way?
这里是否有替代方法,我可以触发以其他方式发送数据模型吗?
Thanks, James 谢谢,詹姆斯
Pull your customer view out of the nib as you would any other custom view Load View from Nib ; 将您的客户视图从笔尖中拉出,就像将其他自定义视图从“笔尖”中加载一样 ; then add it using:
然后使用以下命令添加它:
- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section
edit Sorry, didn't mean to imply that #2 isn't also viable. 编辑抱歉,并不意味着暗示#2也不可行。
- (id)instantiateViewControllerWithIdentifier:(NSString *)identifier
// like this:
UIViewController * vc = [[self storyboard] instantiateViewControllerWithIdentifier:@"TheNewView"]
[self.navigationController pushViewController:vc animated:YES];
Using option 2, Create your segue from the view controller instead of from a specific view or button. 使用选项2,从视图控制器而不是从特定视图或按钮创建序列。 Give it a meaningful identifier, then in the action method for your button, call
performSegueWithIdentifier:sender:
on your view controller. 给它提供一个有意义的标识符,然后在按钮的操作方法中,在视图控制器上调用
performSegueWithIdentifier:sender:
You can pass in any object you like as the view controller, including the index path or an NSNumber holding the section identifier, so you can access this in prepareForSegue and use the appropriate parts of your data model. 您可以传入任何您希望用作视图控制器的对象,包括索引路径或包含节标识符的NSNumber,因此您可以在prepareForSegue中访问它并使用数据模型的适当部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.