2013-08-21 45 views
1

我有問題alertview當我試圖顯示一些文本,如果用戶取消alertivewuialertview與條件if語句在ios

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset 
{ 
    UIALertView alertview = [[UIAlertView alloc] initWithTitle:@"New Answer" 
              message:@"Your text" 
                delegate:self 
                cancelButtonTitle:@"Cancel" 
                otherButtonTitles:@"OK", nil]; 

    [alert show] 

    if (buttonIndex == 0) 
    { 
     NSLog(@"ok"); 
     [[self sectionSelectedDisplay] setText:answerLabel]; 
    } 
    else 
    { 
     NSLog(@"cancel"); 
    } 
} 

+++++++++++++++++++++++++

誰能幫我解決這個問題?

+1

所以,你要的NSLog的alertview按鈕按下的指數? – Woodstock

+0

該問題尚不清楚。你到底需要什麼幫助? –

+0

@Puneet:我編輯了代碼。那是我的功能。這[[self sectionSelectedDisplay] setText:answerLabel];不在if語句內工作。 – Aragon

回答

1

存在UIalertviewdelegate作爲

的功能,如果你有兩個按鈕,然後功能的工作原理如下

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == 1) { 
     // this is normal button 
    }  
    else if (buttonIndex == 0) { 
     // this is cancel button 
    } 
}