2011-09-13 35 views
0

在我的應用程序我有復位按鈕,刪除表中的所有數據,並刪除database.but之前,我必須把警報視圖,並提出這樣的問題如下:警報視圖的方法是行不通的

- (IBAction)resetData:(id)sender 
{ 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Bills Data Entry" 
         message:@"Are you sure want to reset data?" delegate:nil 
         cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]; 
    [alert show]; 
    [alert release]; 
} 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == 1) { 

     [self databaseOpen]; 
     NSString *deleteData=[NSString stringWithFormat:@"delete from tbl_Bills"]; 
     [database executeQuery:deleteData]; 
     NSLog(@"inert query: %@",deleteData); 
     NSLog(@"records deleted"); 
     [table reloadData]; 
     [database close]; 

     // DO STUFF 
    } 
} 

這當我點擊是時,方法不會被調用。

+0

你使用斷點,以確保程序進入方法? – Joze

+0

設置代表自我... – Maulik

回答

4

如果你想調用它的委託方法,UIAlertView的委託不能爲零。

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Bills Data Entry" 
         message:@"Are you sure want to reset data?" delegate:self 
         cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]; 
+0

雅正確他已設置代表爲零,那麼他將如何能夠擊中代表方法...乾杯 – Sabby

1

如果要調用其委託方法,則必須將UIAlertView委託設置爲self。

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Bills Data Entry" 
              message:@"Are you sure want to reset data?" 
              delegate:self 
              cancelButtonTitle:@"No" 
              otherButtonTitles:@"Yes",nil]; 
1
When you are using Delegate method you are supposed to set "delegate: self" instead of nil. 

    UIAlertView *my_Alert = [[UIAlert alloc] initWithTitle:@"Title of Alert" message:@"Your 
          Message" delegate:self cancelButtonTitle:@"OK", 
          otherButtonTitles:nil,nil];