uitabbarcontroller popviewcontrollerAnimatedおよびSelectedIndex(iPhone SDK)のローテーションの問題
質問
これは非常に重要な自動回転問題であり、再現しやすいです。
私のアプリケーションにはuitabbarcontrollerがあります。各タブはuinavigationcontrollerです。自動ローテーションは、interfaceorientationとdidrotate fromInterfaceorientationへの通常の呼び出しで処理されます。
インターフェイスは、uiviewcontroller.popviewcontrollerAnimatedに電話してuitabbarcontroller.selectedIndexを変更するまで正常に回転します。
再現する手順:
- デモタブバーアプリケーションを作成します。
- 次のコードをApp Delegate .hファイルに追加します。
#import <UIKit/UIKit.h>
@interface TestRotationAppDelegate : NSObject { UIWindow *window; UITabBarController *tabBarController; }
@property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end
// Redefine the interface to cach rotation messages @interface UITabBarController (TestRotation1AppDelegate)
@end - 次のコードをアプリDelegate .mファイルに追加します。
#import "TestRotationAppDelegate.h"
@implementation TestRotationAppDelegate @synthesize window; @synthesize tabBarController;
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [window addSubview:tabBarController.view]; [window makeKeyAndVisible]; return YES; }
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; }
-(void)dealloc { [tabBarController release]; [window release]; [super dealloc]; }
@end
@implementation UITabBarController (TestRotation1AppDelegate)
-(void)viewDidLoad { [super viewDidLoad]; // Add a third tab and push a view UIViewController *view1 = [[[UIViewController alloc] init] autorelease]; view1.title = @"Third"; UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:view1] autorelease]; NSMutableArray *array = [[NSMutableArray alloc] init]; [array addObjectsFromArray:self.viewControllers]; [array addObject:nav]; self.viewControllers = array; // Push view2 inside the third tab UIViewController *view2 = [[[UIViewController alloc] init] autorelease]; [nav pushViewController:view2 animated:YES]; // Create a button to pop view2 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(50, 50, 220, 38); [button setTitle:@"Pop this view" forState:UIControlStateNormal]; [button addTarget:self action:@selector(doAction) forControlEvents:UIControlEventTouchUpInside]; [view2.view addSubview:button]; }
-(void) doAction { // ROTATION PROBLEM BEGINS HERE // Remove one line of code and the problem doesn't occur. [self.selectedViewController popViewControllerAnimated:YES]; self.selectedIndex = 0; }
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; }
@end
インターフェイス自動は、タブ#3のボタンをタップするまで正常に回転します。
あなたの助けは喜んで感謝されます!
解決
iPhone SDK 3.2はこの問題を解決します。
以前のSDKを使用して[self.selectedViewController popviewControllerAnimated:no]。
所属していません StackOverflow