2011-09-02 1 views
2

아이디어.tabbar 앱의 tabbaritem에서 액션 시트 호출하기

저는 TabBarController 기반 앱을 개발하고 있습니다.

는 다음과 같은 3 TabBarItems 있습니다

  • 홈이 사용되는 것을하지 않는
  • 콘텐츠 (탐색 컨트롤러 내에있는 contentView를 보여줍니다)
  • 공유 ((탐색 컨트롤러 내에서 homeView를 보여줍니다) to)

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의 뷰로드가 중지되어 Action Sheet가 표시되는 것을 막을 수 있습니까?

내 의견에 대해 감사드립니다.

@Christopher A : 답장을 보내 주셔서 감사합니다.

"projectAppDelegate.m"에 다음 코드를 추가했지만 tabbaritem을 선택할 때 메서드가 호출되지 않았습니다.

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController { 
if ([viewController.title isEqualToString:@"Share"]) { 
    return NO; 
} 
return YES; 

답변

0

tabBarController: shouldSelectViewController:이 값을 프로그래밍 방식으로 설정할 수 있어야합니다. 세부 정보는 here입니다.

+0

질문에 OP 편집을 참조하십시오. –

0

[UIApplication sharedApplication].keyWindow에 시트가 표시되어 있기 때문입니다.

이 하나를 시도

[sheet showInView:self.view]; 
+0

여전히 백그라운드에서보기가 표시됩니다. EDIT : 잘못된보기;) – lug

0

은 [UIApplication sharedApplication]를 .keyWindow 행동을 보여주기 위해 사용하지 마십시오.

로 교체 :

[actionSheet showFromTabBar:self.tabBarController.tabBar]; 

당신이 먼저 당신의 UITabBarController가의 참조를 얻을 당신의 tabBarController 참조를 받고 있지 않은 경우.

0
- (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; 
} 

}

희망은 당신을 도울 수 있습니다.