正确的方法来解决showFromTabBar的顶级UITabBarController视图

时间:2011-05-20 13:58:35

标签: iphone uitabbarcontroller uiactionsheet

主app appate有一个名为tabBarController的UITabBarController(NewsUKDelegate.m)

第一个选项卡加载一个UIViewController,它会添加一个UITableView(FirstViewController.m)

UITableView在选择单元格时加载子类UIViewController(StoryController.m)

然后我从Sharekit

加载共享操作表
NSURL *url = [NSURL URLWithString:link];
SHKItem *item = [SHKItem URL:url title:storyTitle];
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
[actionSheet showFromTabBar:rootView];
[actionSheet showFromTabBar:[self view]];

它有效(ish)但是动作表从顶部加载似乎是错误的,但重要的是它抱怨了

incompatible Objective-C types 'struct UIView *', expected 'struct UITabBar *' 
when passing argument 1 of 'showFromTabBar:' from distinct Objective-C type

我试过用

搞错了
UIWindow *topWindow = [[UIApplication sharedApplication] keyWindow];

if (topWindow.windowLevel != UIWindowLevelNormal)
{
    NSArray *windows = [[UIApplication sharedApplication] windows];
    for(topWindow in windows)
    {
        if (topWindow.windowLevel == UIWindowLevelNormal)
            break;
    }
}

UIView *rootView = [[topWindow subviews] objectAtIndex:0];  
NSLog(@"Root view is: %@",rootView);

[actionSheet showFromTabBar:rootView];
    [actionSheet showFromTabBar:NewsUKDelegate.tabBarController];
    [actionSheet showFromTabBar:NewsUKDelegate.view];

但我只是崩溃了,解决主应用程序代理工具栏的正确方法是什么

2 个答案:

答案 0 :(得分:7)

使用,

[actionSheet showFromTabBar:self.tabBarController.tabBar];

答案 1 :(得分:0)

     ((myAppDelegate *)[UIApplication sharedApplication]).delegate.tabBar