iphone - 将变量传递给使用 presentViewController 加载的 View Controller
<p><p>我在接收 geoPoint 对象的 block 内有这段代码:</p>
<pre><code>UIViewController *mapViewController1 =
[ initWithNibName:@"BSTGMapViewController_iPhone"
bundle:nil];
PFGeoPoint *currentLocation = geoPoint;
;
</code></pre>
<p>如何将 geoPoint 变量传递给 mapViewController1,以便在 </p> 上使用它
<p>viewDidLoad 函数?我使用 XCode 4.6 定位 iOS 5。我该如何解决这个问题?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在 BSTGMapViewController 内部重载 initWithNibName 以传递参数</p>
<p>在 BSTGMapViewController 内部。</p>
<pre><code>- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil withGeoPoint:(CLLocation*)userLocation;
</code></pre>
<p>并在 BSTGMapViewController.m 中实现</p>
<pre><code>- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil withGeoPoint:(CLLocation*)userLocation
{
//usual code of init with nib name
locationhere=userlocation;
}
</code></pre>
<p>//你的代码</p>
<pre><code>PFGeoPoint *currentLocation = geoPoint;
BSTGMapViewController *mapViewController1 =
[ initWithNibName:@"BSTGMapViewController_iPhone"
bundle:nil withGeoPoint:currentLocation];
;
</code></pre></p>
<p style="font-size: 20px;">关于iphone - 将变量传递给使用 presentViewController 加载的 ViewController ,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/15546058/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/15546058/
</a>
</p>
页:
[1]