2

locationUpdate: メソッドに、この iPhone または iPhone 5 の条件ステートメントがあります。

このコードは機能します:

- (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の条件付きコードの場合。失敗します。アプリはクラッシュしませんが、View Controller (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 の else if ステートメントが問題のようです。OffersViewControlleriPhone5 を OffersViewController に変更しても機能しません。

助けてくれてありがとう

4

1 に答える 1

0

ちょうどそれを理解しました。条件に達する前に}閉じたがありました。if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){ if(result.height == 1136) {

于 2013-02-25T13:53:54.353 に答える