从选项卡应用程序中的 tabbaritem 调用操作表
这个想法。
我正在开发一个基于TabBarController的应用程序。
有以下 3 个 TabBarItems:
- 主页(在导航控制器中显示 homeView)
- 内容(在导航控制器中显示 contentView)
- 共享(不执行其惯常操作)
我希望 TabBarItem“共享”显示操作表在当前视图下,不改变视图。
我所做的。
通过以下几行,我可以获得“共享”-TabBarItem 单击/触摸。
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
if ([item.title isEqualToString:@"Share"]) {
actionSheet = [[UIActionSheet alloc] initWithTitle:@"Share this App" delegate:self cancelButtonTitle:@"Cancle" destructiveButtonTitle:nil otherButtonTitles:@"Share on FaceBook", nil];
actionSheet.actionSheetStyle = UIBarStyleBlackTranslucent;
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
[actionSheet release];
}
问题。
每次我选择“共享”时,都会显示一个空白视图。
如何阻止 TabBarItem 加载其视图,从而导致显示操作表?
问候并感谢您考虑我的问题!
@Christopher A:感谢您的回复。
将以下代码放入我的“projectAppDelegate.m”中,但在选择 tabbaritem 时不会调用该方法。
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if ([viewController.title isEqualToString:@"Share"]) {
return NO;
}
return YES;
The idea.
I'm developing a TabBarController based app.
There are the following 3 TabBarItems:
- Home (shows homeView within a navigation controller)
- Content (shows contentView within a navigation controller)
- Share (doesn't do what it's used to)
I'd like the TabBarItem "Share" to show an Action Sheet at the current view, not to change the view.
What I've done.
With the following lines I'm able to get the "Share"-TabBarItem Click/Touch.
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
if ([item.title isEqualToString:@"Share"]) {
actionSheet = [[UIActionSheet alloc] initWithTitle:@"Share this App" delegate:self cancelButtonTitle:@"Cancle" destructiveButtonTitle:nil otherButtonTitles:@"Share on FaceBook", nil];
actionSheet.actionSheetStyle = UIBarStyleBlackTranslucent;
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
[actionSheet release];
}
The problem.
Every time I select "Share", a blank view is shown.
How can I stop the TabBarItem from loading its view, just causing the Action Sheet being shown?
Greets and thank you for thinking about my problem!
@Christopher A: thanks for your response.
Placed the following code in my "projectAppDelegate.m" but the method isn't called when selecting a tabbaritem.
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if ([viewController.title isEqualToString:@"Share"]) {
return NO;
}
return YES;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
tabBarController: shouldSelectViewController:
应该允许您以编程方式设置它。查看它的详细信息 此处。
tabBarController: shouldSelectViewController:
should allow you to programmatically set this.Check out the details of it here.
这是因为您正在
[UIApplication sharedApplication].keyWindow
中显示工作表。试试这个:
This is because you are showing sheet in
[UIApplication sharedApplication].keyWindow
.Try this one:
不要使用 [UIApplication sharedApplication].keyWindow 来显示操作。
将其替换为:
如果您没有获取 tabBarController 引用,则首先获取 UItabbarcontroller 的引用。
Don't use [UIApplication sharedApplication].keyWindow to show action.
Replace it with :
If you are not getting your tabBarController references then first get the reference of your UItabbarcontroller.
希望
对你有帮助。
}
hope to help you.