iOS SDK6:UIViewController有时无法显示

时间:2012-10-22 11:16:32

标签: ios objective-c uiviewcontroller uitableview viewdidappear

我的iOS应用程序(iPhone)出现了一个奇怪的问题,因为我们碰到了XCode 4.5.x& SDK 6.问题是视图控制器大部分时间都显示,但有时不显示。我已经检查过,在所有情况下都会调用viewDidLoadviewWillAppearviewDidAppear委托方法,但这似乎不会影响视图是否显示。

BroadcastOptionsViewController *tmpView = [[BroadcastOptionsViewController alloc] init]; 
[self.navigationController pushViewController:tmpView animated:YES];

我们从多个地方调用此视图控制器(应用程序使用UITabBarController,此代码从两个不同的选项卡调用,两个选项卡都有自己的导航控制器)并且错误似乎表现出来,无论通过哪条路径这样做,这让我怀疑视图控制器本身,或者可能是内存损坏。

我们已经在多个设备(iOS 5.x和6,iPhone 4 / 3GS,iPod touch)上测试了应用程序,它似乎相当随机地发生(例如在'冷启动'之后以及在使用应用程序之后)时间)。

最后,我曾经让BroadcastOptionsViewController成为UITableViewController的子类。我有一个建议是将其设为UIViewController并使用成员UITableView。这似乎减少了问题的发生,但它仍然没有解决它。

修改 曾经有一个用于此视图控制器的XIB(未使用),但已被删除。我关闭了XCode,从设备中删除了应用程序,清除了~/Library/Developer/XCode/DerivedData/*(显然是XCode 4+中的已知错误)。

根据要求,这里还有一些代码:

-(id) init {
    NSLog(@"BroadcastOptionsViewController:init");

    self = [super init];

    if (self) {
        // Some scalar members initialized
    }

    return self;
}


-(void) viewDidLoad {
    NSLog(@"BroadcastOptionsViewController:viewDidLoad");

    [super viewDidLoad];

    int navBarHeight = self.navigationController.navigationBar.frame.size.height;

    tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.bounds.size.height) style:UITableViewStyleGrouped];
    [tableView setFrame:CGRectMake(0, 0, 320, self.view.bounds.size.height - navBarHeight)];

    [tableView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]];
    [tableView setDelegate:self];
    [tableView setDataSource:self];
    [tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.view addSubview:tableView];

    self.title = NSLocalizedString(@"Title", nil);
    self.navigationController.navigationBar.tintColor = [LookAndFeel defaultColor];

    tableView.allowsSelection = YES;

    UIBarButtonItem *btn_cancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)];
    self.navigationItem.leftBarButtonItem = btn_cancel;
    [btn_cancel release];

    UIBarButtonItem *btn_action =
    [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Go", nil)
                                     style:UIBarButtonSystemItemDone
                                    target:self
                                    action:@selector(doAction)];
    self.navigationItem.rightBarButtonItem = btn_action;
    [btn_action release];
}


-(void) viewWillAppear:(BOOL) animated {
    NSLog(@"BroadcastOptionsViewController:viewWillAppear");

    [super viewWillAppear:animated];

    [[UIApplication sharedApplication] setStatusBarHidden:NO];

    // WORKAROUND: Navigation bar hiding below status bar
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    [self.navigationController setNavigationBarHidden:NO animated:NO];

    // Events
    [self subscribeToApplicationEvents];
}


-(void) viewDidAppear:(BOOL)animated {
    NSLog(@"BroadcastOptionsViewController:viewDidAppear");
    // Always properly called, independent of whether view actually appears
}

0 个答案:

没有答案