【发布时间】:2011-11-09 11:23:08
【问题描述】:
想法。
我正在开发一个基于 TabBarController 的应用程序。
有以下3个TabBarItem:
- 主页(在导航控制器中显示主页视图)
- 内容(在导航控制器中显示 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;
【问题讨论】: