[英]perform a method every time a tab is selected
I have tabview based project. 我有基于tabview的项目。 how can I make a view connected to a tab perform a certain method every time the tab is selected?
每次选择选项卡时,如何使连接到选项卡的视图执行某种方法?
Please help, Thanks 请帮忙,谢谢
EDIT: I mistook TabBar for TableView. 编辑:我误认为TableView的TabBar。 I'm sorry for that.
对此我感到抱歉。 I let my old answer being here, it might help you in another problem.
我让我的老答案在这里,这可能会帮助您解决另一个问题。
The answer that bryamac gave you is the right one. bryamac给您的答案是正确的。
When you click the tab then you probably load some UIView to display some content. 当您单击选项卡时,您可能会加载一些UIView来显示一些内容。 For that UIView you must have a controller class.
对于该UIView,您必须具有一个控制器类。 In that controller class there are
- (void)viewDidAppear:(BOOL)animated
and - (void)viewWillAppear:(BOOL)animated
methods which you may use. 在该控制器类中,可以使用
- (void)viewDidAppear:(BOOL)animated
和- (void)viewWillAppear:(BOOL)animated
方法。
Old answer 旧答案
What you want to do is make a class to a UITableViewDelegate. 您想要做的是为UITableViewDelegate创建一个类。
Then you must set this class as the delegate of the UITableView, you can to that in the Interface Builder by right-clicking on the UITableView and dragging its delegate to the class that you have chosen, eg its own controller class. 然后,必须将该类设置为UITableView的委托,然后可以通过在UITableView上单击鼠标右键并将其委托拖到所选的类(例如其自己的控制器类)中,以在Interface Builder中进行设置。
Then you implement this method inside the UITableViewDelegate-class: 然后,您可以在UITableViewDelegate-class内部实现此方法:
– tableView:didSelectRowAtIndexPath;
Assuming the tab var is the main way to make the view appear, you can hook code into: 假定选项卡var是使视图出现的主要方法,则可以将代码挂钩:
- (void)viewDidAppear:(BOOL)animated
or ... 要么 ...
- (void)viewWillAppear:(BOOL)animated
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.