0
UIBarButtonItem* saveButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                                                              target:hvc //other controller
                                                                              action:@selector(save:)];
        UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
                                                                                target:self
                                                                                action:@selector(cancel:)];

        self.navigationItem.rightBarButtonItem = saveButton;
        self.navigationItem.leftBarButtonItem = cancelButton;

I have two buttons being made in a view controller. I'm trying to design the save button to take in the data in some textfields and send it to another view controller, while cancel button just dismisses the current view controller.

Other view controller was initialized in the app delegate file.

How do I define the target for the save button to be this other view controller ?

4

1 回答 1

0

如果您在变量中引用了该视图控制器hvc,那么上面的代码就是要走的路。如果没有得到那个实例。

但是更简洁的方法是仅在显示的视图控制器中处理按钮操作,并从目标处理程序调用其他视图控制器的方法。

因此,您将创建一个调用-(void)handleSave:(id)data;并实现它的方法。并使用该视图控制器类的实例调用该方法。

于 2013-06-20T06:39:12.457 回答