2
我在locationUpdate:方法中有此iPhone或iPhone 5條件語句。iPhone或iPhone 5在locationUpdate方法中的條件語句:方法
此代碼:
- (void)locationUpdate:(CLLocation *)location {
//locLabel.text = [location description];
#ifdef DEBUG
NSLog(@"auth status is %u", [CLLocationManager authorizationStatus]);
#endif
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
OffersViewController *lvc = [storyboard instantiateViewControllerWithIdentifier:@"OffersViewController"];
[self.navigationController pushViewController:lvc animated:NO];
}
但iphone5的條件代碼時。它失敗。該應用程序不會崩潰,但只保留在視圖控制器(RootViewController)上,不會推送到OffersViewController或OffersViewControlleriPhone。
- (void)locationUpdate:(CLLocation *)location {
//locLabel.text = [location description];
#ifdef DEBUG
NSLog(@"auth status is %u", [CLLocationManager authorizationStatus]);
#endif
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 960) {
NSLog(@"iPhone 4 Resolution");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
OffersViewController *lvc = [storyboard instantiateViewControllerWithIdentifier:@"OffersViewController"];
[self.navigationController pushViewController:lvc animated:NO];
}
**else if(result.height == 1136) {
NSLog(@"iPhone 5 Resolution");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
OffersViewControlleriPhone5 *lvc = [storyboard instantiateViewControllerWithIdentifier:@"OffersViewControlleriPhone5"];
[self.navigationController pushViewController:lvc animated:NO];
}**
}
else {
NSLog(@"Standard Resolution");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
OffersViewController *lvc = [storyboard instantiateViewControllerWithIdentifier:@"OffersViewController"];
[self.navigationController pushViewController:lvc animated:NO];
}
}
}
它似乎是其他如果聲明爲iPhone5這是問題。即使我將OffersViewControlleriPhone5更改爲OffersViewController,它也不起作用。
感謝您的任何幫助
你真的不應該這樣做,檢查屏幕大小,因爲任何事情都可以改變它,調用使狀態欄變大,旋轉將它們交換,等等...... – jjv360 2013-02-25 13:53:55
@ jjv360我發現此代碼來檢查適用於iPhone和iPhone5。測試使用哪種設備的更好方法是什麼?謝謝。 – hanumanDev 2013-02-25 13:55:01
嗯,這可能是根據屏幕尺寸顯示不同視圖的最佳方法,但通常視圖應該流動以便它們可以縮放以適合任何屏幕......這樣,您只有一個視圖可以管理和更新不同設備簡單... – jjv360 2013-02-25 13:57:14