【问题标题】:Selector with argument带参数的选择器
【发布时间】:2011-06-17 20:00:34
【问题描述】:

我有一个这样的方法:


- (void)methodWithParameter:(id)parameter {

}

我想用 UIBarButtonItem 来调用它

barButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(methodWithParameter:)];
我想指定参数,但不能使用 withObject: after action: 因为我收到警告:
没有 -initWithBarButtonSystemItem:target:action:withObject: 方法找到

谁能帮我解决这个问题?

【问题讨论】:

    标签: iphone objective-c selector


    【解决方案1】:

    这样不行。您不能将参数传递给操作。一个动作方法总是有:

    • 完全没有参数,
    • 一个参数(id)sender,
    • 或两个参数(id)sender(UIEvent *)event

    【讨论】:

    • 谢谢,我认为唯一的方法是制作另一个没有参数的方法,它调用我的 methodWithParameter: 方法
    猜你喜欢
    • 1970-01-01
    • 2012-04-15
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-23
    • 1970-01-01
    相关资源
    最近更新 更多