2013-03-28 96 views
1

我正在函數quizEnded中創建一個UIActionSheet。 其中一個按鈕將用戶發送到Game Center。當他們從遊戲中心返回時被提問再次被調用到viewdidappear裏面。這是在較舊的一個之上創建第二個操作表。UIActionSheet顯示兩次

https://www.youtube.com/watch?v=QrY1Awt3RX0

我不覺得打電話叫quizEnded再次引起不如說我不正常解聘第一UIActionSheet的問題。

-(void)viewDidAppear { 
// some code ... 
if(self.quizDidEnd > 0){ 
     [BT_debugger showIt:self theMessage:@"@@@Calling quiz ended###"]; 

     [self quizEnded]; 
    } 
}// end viewDidAppear 

// initialize button array 
-(void)quizEnded { 
// some code ... 
    _finishedButtons = [[NSMutableArray alloc] init]; 

    // show either the reward screen or the finished screen or quit to menu 

    if(earnedReward == TRUE && haveRewardScreen==TRUE) { 
     [_finishedButtons addObject:NSLocalizedString(@"quizShowReward", @"Show Reward")]; 
     //[self showQuizRewardScreen]; 

    }else { 
     if(haveFinishScreen==TRUE){ 

      [_finishedButtons addObject:NSLocalizedString(@"continue", @"Continue")]; 
      //[self showFinishScreen]; 

     }else { 
      // if no finish screen then send back to rootviewcontroller 
      [_finishedButtons addObject:NSLocalizedString(@"quit", @"Quit")];    } 
    } 

    if(_enableGameCenter) { 
     [_finishedButtons addObject:NSLocalizedString(@"Game Center", @"Game Center")]; 
    } 

    // initialize UIAction sheet 
    UIActionSheet *actionSheet = [[UIActionSheet alloc] 
            initWithTitle:quizResultMessage 
            delegate:self 
            cancelButtonTitle:nil 
            destructiveButtonTitle:nil 
            otherButtonTitles: nil]; 


    //add the buttons to the action sheet 
    for (int i = 0; i < [_finishedButtons count]; i++) { 
     [actionSheet addButtonWithTitle:[_finishedButtons objectAtIndex:i]]; 
    } 

    actionSheet.destructiveButtonIndex = [_finishedButtons count]; 

    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackOpaque]; 



    //is this a tabbed app? 
    if([appDelegate.rootApp.tabs count] > 0){ 
     [actionSheet showFromTabBar:[appDelegate.rootApp.rootTabBarController tabBar]]; 
    }else{ 
     [actionSheet showInView:self.view]; 
    } 

    [actionSheet release]; 

}//self.quizDidEnd == 0 


}// end quizEnded 

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 


[BT_debugger showIt:self theMessage:@"!!!action sheet called!!!"]; 

NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex]; 

//quit only used if no finished or reward screen present 
if([buttonTitle isEqual:NSLocalizedString(@"quit", @"Quit")]){ 

    // if no finish screen then send back to rootviewcontroller 
    [self.navigationController popToRootViewControllerAnimated:YES]; 
    [BT_debugger showIt:self theMessage:@"Quit tapped"]; 
} 


//show reward 
if([buttonTitle isEqual:NSLocalizedString(@"quizShowReward", @"Show Reward")]){ 
    [self showQuizRewardScreen]; 
    [BT_debugger showIt:self theMessage:@"Show Reward Tapped"]; 
} 

//show continue 
if([buttonTitle isEqual:NSLocalizedString(@"continue", @"Continue")]){ 
    [self showFinishScreen]; 
    [BT_debugger showIt:self theMessage:@"Continue Tapped"]; 
} 

//show game center 
if([buttonTitle isEqual:NSLocalizedString(@"Game Center", @"Game Center")]){ 
    [BT_debugger showIt:self theMessage:@"game center tapped"]; 
    [self showGameCenter]; 
    _altend = 0; 

} 

}// end 
+0

無關的問題,但我相信'actionSheet.destructiveButtonIndex = [_finishedButtons數]'應該是'actionSheet.destructiveButtonIndex = [_finishedButtons計數] - 1'; – 7usam

+0

你在哪裏設置quizDidEnd爲0? – Ric

+0

quizDidEnd在viewDidLoad中設置爲0。然後在測驗結束時翻到1(5,10,20個問題)。 – NadtheVlad

回答

1

你是不是從我所看到的解僱行動表... 必須調用- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated你的動作片將其關閉。

3

如果它是帶來了菜單的手勢,請確保你把你所有的內部代碼:

if(gestureRecognizer.state == UIGestureRecognizerStateBegan) { } 

否則有可能是第二部分所述手勢改變(UIGestureRecognizerStateChanged),這是造成該行動表將雙重激勵。

0

補充一點:

if(recognizer.state == UIGestureRecognizerStateBegan){ 
     UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:@"" 
    } 
0
if(gesture.state == UIGestureRecognizerStateBegan){ 
    UIActionSheet *sheet; 

    sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"" destructiveButtonTitle:nil otherButtonTitles:@"", nil]; 
    [sheet showInView:self.view]; 
}