Проблема поворота UITabBarController с popViewControllerAnimated и selectedIndex (iPhone SDK) - PullRequest
0 голосов
/ 23 апреля 2010

Это очень важный вопрос автоматического поворота, который легко воспроизвести.

Мое приложение имеет UITabBarController. Каждая вкладка является UINavigationController. Автоповорот обрабатывается обычными вызовами shouldAutorotateToInterfaceOrientation и didRotateFromInterfaceOrientation.

Интерфейс вращается нормально, пока я не вызову UIViewController.popViewControllerAnimated и не изменит UITabBarController.selectedIndex.

Шаги для воспроизведения:

  1. Создание демонстрационного приложения панели вкладок.
  2. Добавьте следующий код в файл делегата приложения .h:
    &#35;import <UIKit/UIKit.h><br>
    @interface TestRotationAppDelegate : NSObject  {
        UIWindow *window;
        UITabBarController *tabBarController;
    }<br>
    @property (nonatomic, retain) IBOutlet UIWindow *window;
    @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;<br>
    @end<br>
    // Redefine the interface to cach rotation messages
    @interface UITabBarController (TestRotation1AppDelegate)<br>
    @end
    
  3. Добавьте следующий код в файл делегата приложения .m:
    &#35;import "TestRotationAppDelegate.h"<br>
    @implementation TestRotationAppDelegate
    @synthesize window;
    @synthesize tabBarController;<br>
    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        [window addSubview:tabBarController.view];
        [window makeKeyAndVisible];
        return YES;
    }<br>
    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return YES;
    }<br>
    -(void)dealloc {
        [tabBarController release];
        [window release];
        [super dealloc];
    }<br>
    @end<br>
    @implementation UITabBarController (TestRotation1AppDelegate)<br>
    -(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];
    }<br>
    -(void) doAction {
        // ROTATION PROBLEM BEGINS HERE
        // Remove one line of code and the problem doesn't occur.
        [self.selectedViewController popViewControllerAnimated:YES];
        self.selectedIndex = 0;
    }<br>
    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return YES;
    }<br>
    @end
    

Интерфейс автоматически вращается, пока вы не нажмете кнопку на вкладке №3.

Ваша помощь будет высоко оценена!

1 Ответ

0 голосов
/ 30 августа 2010

iPhone SDK 3.2 решает эту проблему.

В предыдущем SDK используйте [self.selectedViewController popViewControllerAnimated: NO].

...