CollectionView中的UIMenu弹出窗口 [英] UIMenu popovers in CollectionView

查看:145
本文介绍了CollectionView中的UIMenu弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我设置弹出窗口的方式

This is how i set up the popovers

UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"Delete Patient"

                                                  action:@selector(customAction:)];



[[UIMenuController sharedMenuController] setMenuItems:@[menuItem]];

然后添加require方法

and then add the require methods

- (BOOL)canBecomeFirstResponder {

return YES;

}



- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {



NSLog(@"canPerformAction");

// The selector(s) should match your UIMenuItem selector

if (action == @selector(customAction:)) {

    return YES;

}

return NO;

}



- (void) customAction:(id) sender

{

for (Treatment *t in self.ptToDelete.patientRx) {

    [self.managedObjectContext deleteObject:t];

}



[self.managedObjectContext deleteObject:self.ptToDelete];



NSError *error = nil;

if (![self.managedObjectContext save:&error]) {

    NSLog(@"Error! %@", error);

}

}

这适用于iOS6,但现在不适用.下面的方法没有被调用,当我点击并按住时应该调用它

This works for iOS6, but now it is not. The following method is not getting called, it should be called when I tap and hold

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender

推荐答案

我发现我需要在CollectionViewCell类中包含以下内容.但是,这在ios6中不是必需的.希望这可以节省一个人几个小时.

I found that I needed to have the following in my CollectionViewCell class. This was not required in ios6 however. Hope this saves someone a few hrs.

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender 
{

    // The selector/s should match your UIMenuItem selector
    if (action == @selector(customAction:)) {
        return YES;
    }
        return NO;
    }

- (void) customAction:(id)sender
{
    // do stuff
}

这篇关于CollectionView中的UIMenu弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆