2014-07-16 75 views
0

當您長時間按下我的應用程序中的項目時,會彈出一個UIMenuController並給我幾個選項。其中之一是刪除。使用UIActionSheet添加刪除確認

這裏是什麼樣子的例子:

- (void)messageCellDidLongPress:(FCIMessageCell *)cell 
{ 
self.cellShowingMenuController = cell; 
[self becomeFirstResponder]; 
self.messageMenuController    = [UIMenuController sharedMenuController]; 
self.messageMenuController.anchorView = cell.bodyLabel; 
self.messageMenuController.presentInView = cell; 
[self.messageMenuController updatePosition]; 
UIMenuItem *editMenuItem = [[UIMenuItem alloc] initWithTitle:@"Edit" action:@selector(edit:)]; 
UIMenuItem *unsendMenuItem = [[UIMenuItem alloc] initWithTitle:@"Unsend" action:@selector(unsend:)]; 
UIMenuItem *infoMenuItem = [[UIMenuItem alloc] initWithTitle:@"Details" action:@selector(info:)]; 
self.messageMenuController.menuItems = @[unsendMenuItem, editMenuItem, infoMenuItem]; 
[self.messageMenuController setMenuVisible:YES animated:YES]; 
//Delete button doesn't appear because its set up to appear on conditions 
} 

我想做的事:一旦有人按下刪除鍵有一個「確認」或「取消」選項出現,可能使用一個UIActionSheet。我不太確定該怎麼做。我會在哪裏放置代碼使其顯示。我不確定是否需要創建一個完整的其他視圖,或者是什麼?

+0

問題是什麼?如何在你的-edit:方法中創建一個UIActionSheet? – SwiftArchitect

+0

對不起,我編輯它是一個更加清晰,但我真的不知道該怎麼做。我知道我想要什麼,但我不知道如何設置它 – user3786510

回答

0

在.H

@interface MyViewController : UIViewController <UIActionSheetDelegate> 

在.M

-(IBAction) edit:(id)sender 
{ 
    self.editSheet = [[UIActionSheet alloc] initWithTitle:nil 
     delegate:self 
     cancelButtonTitle:@"cancel" 
     destructiveButtonTitle:@"delete" 
     otherButtonTitles:nil]; 
    [self.editSheet showFromBarButtonItem:sender animated:YES]; 
} 

,後來,在.M

- (void)actionSheet:(UIActionSheet *)actionSheet 
    clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (self.editSheet == actionSheet) { 

    if((actionSheet.cancelButtonIndex) == buttonIndex) { 
      // Cancel, do nothing 
    } // etc. 
} 

還有更多的有點,就像沒有建立如果它已經存在,可能處理iPhone & iPad不同,等等。