NSNotification 的问题关闭模态视图控制器
因此,我有一个 tabbarcontroller,当触摸特定的 tabBarItem
时,我会向 dismissModalViewController
传递通知。
它运行良好,模态视图控制器已被关闭。但我想以特定的方式更改它,但它并不像我期望的那样工作...
我在发布通知之前初始化了观察者。这些是 tabBarItems -
NSArray *viewControllerss = [[NSArray alloc] initWithObjects: myProfileDataViewController,
sampleViewController,reminderInfoViewController, nil];
[self.tabBarContr setViewControllers:viewControllerss animated:YES];
self.tabBarContr.selectedIndex = 2;
我在 sampleViewController
的 viewWillAppear
上发送通知,当我选择该 tabBarIcon 时,它会关闭 TabBarController。
但我希望 sampleViewController
位于 UITabBar
的最左侧。
所以我添加它就像
NSArray *viewControllerss = [[NSArray alloc] initWithObjects: sampleViewController,
myProfileDataViewController, reminderInfoViewController, nil];
这样不会关闭选项卡栏控制器。
注意: 请查看 NSArray 初始化的顺序。
通知发布在 viewWillAppear
sampleViewController` 和观察者在各自的视图控制器中呈现模式视图控制器
So, I have a tabbarcontroller, and I pass a notification to dismissModalViewController
when a particular tabBarItem
is touched.
It is working well and the modal View Controller is dismissed. But I want to change it in a particular way, and it does not work as I expect it to...
I have the observer initialized before the notification is posted. These are the tabBarItems -
NSArray *viewControllerss = [[NSArray alloc] initWithObjects: myProfileDataViewController,
sampleViewController,reminderInfoViewController, nil];
[self.tabBarContr setViewControllers:viewControllerss animated:YES];
self.tabBarContr.selectedIndex = 2;
I send a notification on the viewWillAppear
of sampleViewController
and when I choose that tabBarIcon, it dismisses the TabBarController.
BUT I want the sampleViewController
to be on the left most of the UITabBar
.
And so I add it like
NSArray *viewControllerss = [[NSArray alloc] initWithObjects: sampleViewController,
myProfileDataViewController, reminderInfoViewController, nil];
THIS DOES NOT DISMISS TAB BAR CONTROLLER.
Note: Please see the order in which NSArray is initialized.
The notification is posted in the viewWillAppear of
sampleViewController` and observer in the respective view controller which presents the modal view controller
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你能在发布通知之前先放一个 NSLog 吗?
查看应用程序加载时是否获得任何输出。
编辑:根据您的响应添加答案
在您的sampleViewController中您可以尝试以下操作:
使其符合UITabBarControllerDelegate。您的sampleViewController类接口应该是这样的:
然后在sampleViewController的.m中,在viewDidLoad中,将委托设置为sampleViewController(在本例中为self)
现在在sampleViewController.m文件中的某处实现委托方法。
看看是否有效。
Could you put a NSLog right before you post the notification?
See if you get any output when the app loads.
EDIT: Adding onto the answer based on your response
In your sampleViewController could you try this:
Make it conform to the UITabBarControllerDelegate. Your sampleViewController class interface should be something like this:
Then in the .m of your sampleViewController, in the viewDidLoad, set the delegate to be the sampleViewController (self in this case)
Now implement the delegate method somewhere inside the sampleViewController .m file.
See if that works.