2011-05-20 49 views
2

主应用程序委托顶视图的UITabBarController正确方法具有的UITabBarController称为tabBarController(NewsUKDelegate.m)以解决showFromTabBar

第一个标签加载一个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]]; 
加载份额actionsheet

它的工作原理(ISH),但是从它似乎是错误的顶部actionsheet加载,但重要的是它抱怨的

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]; 

鬼混,但我只是得到崩溃,有什么解决的主要应用程序的委托工具栏

回答

7

正确的使用方法,

[actionSheet showFromTabBar:self.tabBarController.tabBar]; 
+0

一个神奇的组合;)作品一个款待谢谢你! – JulianB 2011-05-20 15:30:08

+0

我在这行上遇到崩溃! :( – 2014-08-31 14:19:49

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

使用karim的解决方案,因为我必须导入应用程序委托标题,所以tabBarController已经定义,但你的看起来更好用于更通用的用途,谢谢。 – JulianB 2011-05-20 15:31:36

+0

@JulianB - Karim的解决方案使用的标点符号少于我的,所以更好定义:-) – Rayfleck 2011-05-20 15:35:00