从选项卡应用程序中的 tabbaritem 调用操作表

发布于 2024-12-02 20:50:13 字数 1276 浏览 3 评论 0原文

这个想法。

我正在开发一个基于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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

归途 2024-12-09 20:50:13

tabBarController: shouldSelectViewController: 应该允许您以编程方式设置它。
查看它的详细信息 此处

tabBarController: shouldSelectViewController: should allow you to programmatically set this.
Check out the details of it here.

萌梦深 2024-12-09 20:50:13

这是因为您正在 [UIApplication sharedApplication].keyWindow 中显示工作表。

试试这个:

[sheet showInView:self.view];

This is because you are showing sheet in [UIApplication sharedApplication].keyWindow.

Try this one:

[sheet showInView:self.view];
屋檐 2024-12-09 20:50:13

不要使用 [UIApplication sharedApplication].keyWindow 来显示操作。

将其替换为:

[actionSheet showFromTabBar:self.tabBarController.tabBar];

如果您没有获取 tabBarController 引用,则首先获取 UItabbarcontroller 的引用。

Don't use [UIApplication sharedApplication].keyWindow to show action.

Replace it with :

[actionSheet showFromTabBar:self.tabBarController.tabBar];

If you are not getting your tabBarController references then first get the reference of your UItabbarcontroller.

唠甜嗑 2024-12-09 20:50:13
 - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController: (UIViewController *)viewController
{
//    UIActionSheet *actionSheet = nil;
switch (tabBarController.selectedIndex) {
    case 1:
    {
        NSLog(@"item 1");
        UIActionSheet *shareAS = [[UIActionSheet alloc]
                                      initWithTitle:nil
                                      delegate:self
                                      cancelButtonTitle:@"cancel"
                                      destructiveButtonTitle:nil
                                      otherButtonTitles:@"shareToXX", @"shareToYY",nil];
        shareAS.actionSheetStyle = UIActivityIndicatorViewStyleWhite;
        shareAS.tag = 1;
        [shareAS showInView:self.window];
    }
        break;
    case 2:
    {
        NSLog(@"item 2");
       UIActionSheet *myAS = [[UIActionSheet alloc]
                                      initWithTitle:nil
                                      delegate:self
                                      cancelButtonTitle:@"cancel"
                                      destructiveButtonTitle:nil
                                      otherButtonTitles:@"AAA", @"BBB",@"CCC",@"DDD",nil];
        myAS.actionSheetStyle = UIActionSheetStyleBlackOpaque;
        myAS.tag = 2;
        [myAS showInView:self.window];
    }
        break;
    default:
        break;
}

希望

对你有帮助。

 - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController: (UIViewController *)viewController
{
//    UIActionSheet *actionSheet = nil;
switch (tabBarController.selectedIndex) {
    case 1:
    {
        NSLog(@"item 1");
        UIActionSheet *shareAS = [[UIActionSheet alloc]
                                      initWithTitle:nil
                                      delegate:self
                                      cancelButtonTitle:@"cancel"
                                      destructiveButtonTitle:nil
                                      otherButtonTitles:@"shareToXX", @"shareToYY",nil];
        shareAS.actionSheetStyle = UIActivityIndicatorViewStyleWhite;
        shareAS.tag = 1;
        [shareAS showInView:self.window];
    }
        break;
    case 2:
    {
        NSLog(@"item 2");
       UIActionSheet *myAS = [[UIActionSheet alloc]
                                      initWithTitle:nil
                                      delegate:self
                                      cancelButtonTitle:@"cancel"
                                      destructiveButtonTitle:nil
                                      otherButtonTitles:@"AAA", @"BBB",@"CCC",@"DDD",nil];
        myAS.actionSheetStyle = UIActionSheetStyleBlackOpaque;
        myAS.tag = 2;
        [myAS showInView:self.window];
    }
        break;
    default:
        break;
}

}

hope to help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文