gpt4 book ai didi

iphone - 将变量传递给使用 presentViewController 加载的 View Controller

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:47:14 26 4
gpt4 key购买 nike

我在接收 geoPoint 对象的 block 中有这段代码:

UIViewController *mapViewController1 =
[[BSTGMapViewController alloc] initWithNibName:@"BSTGMapViewController_iPhone"
bundle:nil];
PFGeoPoint *currentLocation = geoPoint;
[self presentViewController:mapViewController1 animated:1 completion:nil];

如何将 geoPoint 变量传递给 mapViewController1,以便我可以在

viewDidLoad 函数?我使用 XCode 4.6 以 iOS 5 为目标。我该如何解决这个问题?

最佳答案

在 BSTGMapViewController 内部重载 initWithNibName 以传递参数

在 BSTGMapViewController 中。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil withGeoPoint:(CLLocation*)userLocation;

并在BSTGMapViewController.m中实现

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil withGeoPoint:(CLLocation*)userLocation
{
//usual code of init with nib name
locationhere=userlocation;

}

//你的代码

PFGeoPoint *currentLocation = geoPoint;
BSTGMapViewController *mapViewController1 =
[[BSTGMapViewController alloc] initWithNibName:@"BSTGMapViewController_iPhone"
bundle:nil withGeoPoint:currentLocation];

[self presentViewController:mapViewController1 animated:1 completion:nil];

关于iphone - 将变量传递给使用 presentViewController 加载的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15546058/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com