0

使用情节提要,我构建了一个带有“添加”按钮的 ViewController1。单击添加显示一个 PopoverView(在 ViewController2 中),其中只有一个 Picker。

所以我的 PickerView 的委托在 ViewController 2 中,但我希望它在 ViewController1 中......有没有简单的方法可以做到这一点?

谢谢

4

2 回答 2

1

In your ViewController1 prepareForSegue method, try this:

if ([segue.identifier isEqualToString:@"MySegue"])
{
    ViewController2* vc2 = segue.destinationViewController;
    vc2.pickerView.delegate = self;
}

It basically assigns the delegate of the pickerview to ViewController1 before the segue is finished being called.

This of course is assuming your pickerview is setup as a property.

于 2012-05-05T22:30:27.363 回答
0

在您的 ViewController1.h 文件中,将您的界面标题更改为此;

@interface ViewController1 : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>;

这使您的 ViewController1 负责代表。然后在 ViewController1.m 文件中添加你想要的方法。此外,将 UIPickerView 的委托设置为您的 ViewController1 实例:

[yourPickerview setDelegate:ViewController1];
于 2012-05-05T21:28:53.887 回答