当你长按我的应用程序中的项目时,会弹出UIMenuController并给我一些选项。其中一个是删除。
以下是一个示例:
- (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 :(得分: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。 iPad不同等等。