0

这行代码在 AController.m

UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
    initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
    target:self
    action:@selector(addItem)];

和 - (void) addItem:(id) 发件人;也在 AController.m

如果我想调用一个方法 - (void) addItem1:(id) sender; 在 BController.m 中,我该如何更改才能使其工作?我应该将什么传递给目标参数?

非常感谢!

4

2 回答 2

0

你应该传递一个 BContorller 的实例。如果你想要更多,请发表评论,我会在 1 小时内看到我有空时能做什么。

    BCont=[[BController alloc] init];
    UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
    initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
    target:BCont
    action:@selector(addItem)];

试试看。

于 2010-06-09T15:31:35.517 回答
0

您必须传递 BController 的实时实例。

顺便说一句,动作方法在技术上应该具有以下形式:

- (void) actionName:(id) sender;

只是带有 sender 参数的名称可以工作,但有时运行时会变得很短。

于 2010-06-09T15:32:30.570 回答