将变量从ViewController传递到UIPopoverControllerView iOS

时间:2013-04-11 12:32:48

标签: ios uiviewcontroller uipopovercontroller

我在将视图控制器中的变量传递给UIPopoverViewcontroller

时遇到问题

逻辑与在两个通常的viewControllers之间传递数据不一样吗?

即在view1&中设置变量view2并合成然后呈现PopoverView将变量从view1传递给view2?

我真的很挣扎这个我已经阅读了一些关于协议但是如果它像通常的视图控制器一样工作似乎有点过分了吗?

一个例子

    self.optionsPopover.delegate = self;
    popOverViewController = [[PopOverViewController alloc]initWithNibName:@"PopOverViewController" bundle:nil];
    self.optionsPopover = [[UIPopoverController alloc]initWithContentViewController:popOverViewController];

    //dictionary to pass from view1 to view2 which is a popover
    self.popOverViewController.statsDict = self.statsDict;
    [self.optionsPopover setPopoverContentSize:CGSizeMake(320, 480)];
    [self.optionsPopover presentPopoverFromBarButtonItem:optionsButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

3 个答案:

答案 0 :(得分:0)

UIPopOverViewController将允许您展示自己的UIViewController(充当容器)。就像收到UINavigationController的{​​{1}}一样。你想在UIViewController做什么?

答案 1 :(得分:0)

initWithContentViewController后,您的popOverViewController viewDidLoad方法已被调用(statsDict属性为nil的时间。)

因此,要么在调用初始化程序之前设置属性,要么编写自定义setter,如:

- (void)seStatsDict(NSDictionary *)statsDict
{
    _statsDict = statsDict;
    if (self.view) {
        // Set UILabel texts, etc...
    }
}

答案 2 :(得分:0)

除了在创建popover之前设置popOver的委托之外,代码没有任何问题。我改变了订单。并检查你的字典是否为

self.popOverViewController = [[PopOverViewController alloc]initWithNibName:@"PopOverViewController" bundle:nil];

 //dictionary to pass from view1 to view2 which is a popover
//self.popOverViewController.statsDict = self.statsDict;

 self.popOverViewController.testString = @"testing"; // This is for testing only

 self.optionsPopover = [[UIPopoverController alloc]initWithContentViewController:popOverViewController];
 self.optionsPopover.delegate = self;

[self.optionsPopover setPopoverContentSize:CGSizeMake(320, 480)];
[self.optionsPopover presentPopoverFromBarButtonItem:optionsButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];