中分配值我試圖讓我的iPad應用程序通用。不過,我有一個小問題。我有這個代碼。在我的masterviewcontroller中,根據選擇的國家/地區,所述國家/地區被傳遞到我的detailviewcontroller,我的國家被加載到我的detailview中。無法在iphone版本的程序
我的問題是,當這個代碼在我的iphone上運行時,我的activecountry爲null。但是當它在ipad上運行時,它有一個值。我爲iPhone版選擇了正確的類,我不完全確定爲什麼,因爲我的iphone故事板中有detailviewcontroller視圖。
因此,我的問題是,什麼阻止我將我的價值傳遞到self.detailviewcontroller.activecountry。
想得到任何幫助,我可以解決這個問題。
謝謝
PS。 ipad版本上的ipad detailview控制器是uisplitview控制器的詳細版本。
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
lat = 15.4166152;
lon =-61.353149;
[self.detailViewController animateToPosition:MaplyCoordinateMakeWithDegrees(lon,lat) time:1.0 height:0.1];
ThridViewController *thrid=[[ThridViewController alloc]init];
[self.navigationController pushViewController:thrid animated:YES];
[thrid setTitle:@"America"];
[email protected]"America";
NSLog(@"The active country is %@",self.detailViewController.activeCountry);
}
else
{
lat = 15.4166152;
lon =-61.353149;
[self.detailViewController animateToPosition:MaplyCoordinateMakeWithDegrees(lon,lat) time:1.0 height:0.1];
ThridViewController *thrid=[[ThridViewController alloc]init];
[self.navigationController pushViewController:thrid animated:YES];
[thrid setTitle:@"America"];
[email protected]"America";
NSLog(@"The active country is %@",self.detailViewController.activeCountry);
}
}
更新 我想我發現了什麼。
在我的應用程序委託中,在聲明我的iPad正在運行的代碼中,我調用了detailview控制器上的init,但在iPhone中我沒有這樣的事情。主要導致我不知道如何。因爲我的detailviewcontroller沒有開始看到。
更新,應用代理
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[DBAccess copyDatabaseIfNeeded];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
//Place iPhone code
} else {
// Place iPad-specific code here...
MasterViewController *left=[[MasterViewController alloc]init];
UINavigationController *navigLeft=[[UINavigationController alloc]initWithRootViewController:left];
DetailViewController *detail=[[DetailViewController alloc]init];
UINavigationController *navigRight=[[UINavigationController alloc]initWithRootViewController:detail];
left.detailViewController = detail;
UISplitViewController *splitViewController=[[UISplitViewController alloc]init];
splitViewController.delegate=detail;
splitViewController.viewControllers=[NSArray arrayWithObjects:navigLeft,navigRight,nil];
}
return YES;
}
爲什麼不向我們展示您的應用代理的iPad代碼,我們將看到我們需要爲iPhone做些什麼。 – Fluffhead
@Fluffhead嗨,我添加了應用程序委託代碼。我不確定何時初始化我的detailviewcontroller。我正在考慮在我的主視圖上做一些類似於uipopover的事情(蘋果是否允許在iPhone應用程序中使用uipopover?或者僅僅是ipad。我看到一個人在做YouTube視頻,所有人都告訴他他的應用程序將被拒絕) – Sammie
Sammie,你可以使用UIView來「僞造」彈出窗口,或者嘗試一個自定義的類,例如:http://stackoverflow.com/questions/3987218/uipopover-for-iphone-or-is-it-fake。 – Fluffhead