相关疑难解决方法(0)

带有@selector和动态方法的动态UIMenuItems

我正在尝试使用UIMenuController进行动态菜单(标题和操作来自服务器).问题是我必须使用UIMenuItems initWithTitle:action:其中action是@selector.

我可以使用@selector(dispatch :),但后来我无法区分用户按下的项目. - (void)dispatch:(id)sender {NSLog(@"%@",sender); 说它是一个UIMenuController,它没有一个方法可以告诉哪个菜单项被按下了.

我不能只写100个方法来调度每个可能的选择器,好吧不会有超过10但仍然,这似乎不是一个好主意.

我是否必须为每个这样的选择器创建动态方法?http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtDynamicResolution.html?这看起来也很奇怪.

那么这两个更好的命题呢?

//这种方法不起作用

- (void)showMenu {

    [self becomeFirstResponder];

    NSMutableArray *menuItems = [[NSMutableArray alloc] init];

    UIMenuItem *item;
    for (MLAction *action in self.dataSource.actions) {
        item = [[UIMenuItem alloc] initWithTitle:action.title action:@selector(action:)];
        [menuItems addObject:item];
        [item release];
    }

    UIMenuController *menuController = [UIMenuController sharedMenuController];
    menuController.menuItems = menuItems;
    [menuItems release];
    [menuController update];
    [menuController setMenuVisible:YES animated:YES];

}

- (void)action:(id)sender {
    NSLog(@"%@", sender); // gives UIMenuController instead of UIMenuItem
    // I can not know which menu item was …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uimenucontroller

9
推荐指数
1
解决办法
4528
查看次数

标签 统计

iphone ×1

objective-c ×1

uimenucontroller ×1