2013-02-20 20 views
7

Tôi đang cố gắng trình bày một UITableView mà tôi đã tạo cho người dùng để đưa vào dữ liệu và lưu vào phân tích cú pháp. Tôi khá chắc chắn tôi không trình bày chế độ xem điều hướng.Hiện tại trong khi đang trình bày? Đang cố gắng hiển thị chế độ xem mới sau khi đăng nhập facebook bằng phân tích cú pháp.

Khi tôi đăng nhập, tôi nhận được lỗi:

Checklists[4516:c07] Warning: Attempt to present <ChecklistsViewController: 0x10525e90> 
on <UINavigationController: 0x9648270> while a presentation is in progress! 

Nhờ sự giúp đỡ của bạn.

#import "LoginViewController.h" 
#import "ChecklistsViewController.h" 
#import "SetupViewController.h" 
#import <Parse/Parse.h> 

@interface LoginViewController() 

@end 

@implementation LoginViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 

    PFLogInViewController *login = [[PFLogInViewController alloc] init]; 
    login.fields = PFLogInFieldsFacebook; 
    // Need to set the delegate to be this controller. 
    login.delegate = self; 
    login.signUpController.delegate = self; //signUpController is a property on the login view controller 
    [self presentModalViewController:login animated:NO]; 

} 

    - (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
    NSLog(@"Successfully logged in."); 
    ChecklistsViewController *controller = [[ChecklistsViewController alloc] initWithStyle:UITableViewStylePlain]; 
    controller.modalTransitionStyle = UITableViewStylePlain; 
    [self presentModalViewController:controller animated:YES]; 

} 

Trả lời

34

Phương pháp này đã được chấp thuận cho một tốt khi

 presentModalViewController:animated: 

Bạn nên sử dụng này để thay thế

presentViewController:animated:completion: 

Cùng đi cho này

dismissModalViewControllerAnimated: 

Bây giờ chúng ta sử dụng này

dismissViewControllerAnimated:completion: 

Khi chúng tôi không muốn khối hoàn thành, chúng tôi chỉ đặt thành 0.

Nhưng trong trường hợp của bạn, khối hoàn thành có thể khắc phục sự cố của bạn ... nó đảm bảo chuỗi sự kiện đúng, tức là việc trình diễn sẽ không diễn ra cho đến khi việc hủy hoàn tất.

- (void)logInViewController:(PFLogInViewController *)logInController 
        didLogInUser:(PFUser *)user 
{ 
    [self dismissViewControllerAnimated:YES completion:^{ 
     NSLog(@"Successfully logged in."); 
     ChecklistsViewController *controller = 
       [[ChecklistsViewController alloc] initWithStyle:UITableViewStylePlain]; 
     controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
     [self presentViewController:controller animated:YES completion:nil]; 
    }]; 

} 

[NB - modalTransitionStyle không chính xác trong mã ban đầu của bạn, tôi cũng đã thay đổi điều đó. Cảm ơn Daniel G vì đã chỉ ra điều này]

+0

Cảm ơn! Rất kỹ lưỡng. Nếu bạn không phiền, tôi có một lỗi khác vừa xuất hiện sau khi triển khai giải pháp của bạn. "Cảnh báo: Cố gắng hiển thị trên chế độ xem không nằm trong hệ thống phân cấp cửa sổ!" Chưa thấy cái này. – STANGMMX

+0

@STANGMMX - Tôi sẽ cần biết thêm về ứng dụng của bạn - những gì 'UINavigationController' (hoặc phân lớp) nó sẽ được đề cập đến? Có lẽ một câu hỏi khác cho thấy một chút thông tin như bảng phân cảnh của bạn, bất kỳ manh mối nào khác .. mặc dù có một điều để thử có thể là di chuyển mã của bạn ra khỏi chế độ xemDidAppear - bạn có một tình huống nhầm lẫn khi viewDidAppear được gọi mỗi khi bạn loại bỏ màn hình đăng nhập của mình. Hoặc tạo cờ BOOL để đảm bảo bạn không cố gắng trình bày lại thông tin đăng nhập của mình ngay sau khi bạn đã loại bỏ nó. – foundry

Các vấn đề liên quan