2012-09-25 29 views
0

的iOS: 我的應用程序,打開一些內容,我已經加入了右側導航欄,可以從保存的抓刪除郵件內容的按鈕,現在我希望把構象的行動,按鈕導航控制器上的iOS與刪除actionSheet

sheet = [[UIActionSheet alloc] initWithTitle:@"Delete Message" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete Message" otherButtonTitles:nil]; 
// view sheet 
[sheet showInView:self.view]; 
NSLog(@"Button %d", buttonIndex); 

現在,我怎麼使用我的deleteContent功能這個值:刪除消息, 我創建UIActionsheet這樣之前,用戶符合? 我刪除功能

-(void) deleteContent 
{ 
    if (buttonIndex=0) 
    { 
     [[NSFileManager defaultManager] removeItemAtPath:fileName error:&e]; 
    } 
} 

我的問題是我怎麼能在短短的一個功能,可以在一個呼叫被調用,所有這一切重新排列這一點。

回答

1

這並不是做到這一點。從呼叫按鈕的功能在導航欄中呈現的動作片。然後實現UIActionSheetDelegate方法actionSheetDidDismissWithButtonIdex把你的實際刪除的車。

編輯:如果你需要傳遞從導致要呈現的動作片的方法來刪除該項目的身份,只需添加一個參數,你presentActionSheet方法,並通過該項目。有

+0

THNAKS THANKS THANKS :)它的工作.... – Dixit

+0

很酷。如果我的回答很有幫助,請將複選標記放在它旁邊:) – geraldWilliam

0

人同一個問題:

製作一個功能按鈕,可以調用彈出如下:

-(void)popUp 
{ 

    sheet = [[UIActionSheet alloc] initWithTitle:@"Are you Sure?" 
             delegate:self 
           cancelButtonTitle:@"Cancel" 
          destructiveButtonTitle:@"Delete Message" 
           otherButtonTitles:nil]; 
    // Show the sheet 
    [sheet showInView:self.view]; 
    //[sheet release]; 
    NSLog(@"Button %d", buttonIndex); 
} 

,比創建一個多的功能,處理基於這樣的彈出操作刪除部分:

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex 
    { 
     if (buttonIndex == 0) { //delete it 

      //delete from database 
      //delete from folder 
      [[NSFileManager defaultManager] removeItemAtPath:fileName error:&e]; 
      //close 
      [[self navigationController] popViewControllerAnimated: YES]; 
     }else if { 
      NSLOG(@"USER said No"); 
     } 

    }