3

私は iOS 開発に不慣れで、に取り組んでいUIMenuControllerます。それぞれに異なるセレクターが必要なようUIMenuItemです。

単一のセレクターを使用して、クリックした項目を判別する方法はありますか?

クリックしたアイテムを特定できるように、セレクターに引数を送信できますか?

これは、メニュー項目を初期化する方法です。

UIMenuItem *item = [[UIMenuItem alloc]initWithTitle:@"Item 1" action:@selector(itemClicked:)];
4

1 に答える 1

1

ブロックを使用して、このように委任を処理できます

UIMenuItem.h

@property (nonatomic, copy) void (^onButtonClicked)(id btn);

UIMenuItem.m

@synthesize onButtonClicked;

- (IBAction)btnExpandClicked:(id)sender{

  self.onButtonClicked(sender);
}

各メニュー項目に接続されます

次に、あなたの UITableViewController.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath        *)indexPath {
...
item.onButtonClicked = ^(id btn) {
        // code that will run when the menu item is clicked "not the row of the table"
        // btn is the menu button clicked, you can implement a pop up based on each menu button clicked ( based on the tag for example )
    };
于 2014-01-10T11:59:19.323 に答える