2011-11-10 90 views
0

我有一個分段控件,點擊後用戶將被強制輸入密碼。從委託方法執行segue

成功檢查模態屏幕應該關閉,並在控制器與分段控制一個方法被調用,並應該執行一個segue到另一個控制器。

該segue本身工作,但不是登錄檢查後。我認爲這是與「自我」的問題......

代碼委託類的:

@protocol LoginUserControllerDelegate 
    - (void)proceedAfterLogin:(BOOL)proceedToNextController; 
@end 

@interface LoginUserController : UIViewController { 
    IBOutlet UITextField *loginPWD; 
    id<LoginUserControllerDelegate> _delegate; 

} 

@property (nonatomic, retain) UITextField *loginPWD; 
@property (nonatomic, assign) id<LoginUserControllerDelegate> delegate; 

- (void)checkLogindata; // checks for correct password 
@end 

@implementation LoginUserController 

@synthesize loginPWD; 
@synthesize delegate = _delegate; 

- (void)checkLogindata { 
    ... 
    if ([tempDBPWD isEqualToString:tempLoginPWD]) { 
     if (_delegate != nil) { 
       [self dismissModalViewControllerAnimated:YES]; 
       [_delegate proceedAfterLogin:YES]; 
      } 

    } 
    ... 
} 

@end 

與方法分段控制:

@interface StartViewController : UIViewController <LoginUserControllerDelegate> { 
    UISegmentedControl *segmentedControl; 
    LoginUserController *_loginUserController; 
} 

@property (nonatomic,retain) IBOutlet UISegmentedControl *segmentedControl; 
@property (nonatomic, retain) LoginUserController *loginUserController; 

- (IBAction)segmentedControlIndexChanged:(id)sender; 
@end 


@implementation StartViewController 

@synthesize segmentedControl; 
@synthesize loginUserController = _loginUserController; 


- (IBAction)segmentedControlIndexChanged:(id)sender 
{ 
    if (self.segmentedControl.selectedSegmentIndex == 0) { 
     // get delegate 
     AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
     UIStoryboard *storyboard = appDelegate.window.rootViewController.storyboard; 
     LoginUserController *loginUserControllerView = [storyboard instantiateViewControllerWithIdentifier:@"LoginUserViewID"];  
     loginUserControllerView.delegate = self; 
     // now show screen 
     [self presentModalViewController:loginUserControllerView animated:YES]; 

    } else { 

    } 

} 

- (void)proceedAfterLogin:(BOOL)proceedToNextController 
{ 
    if (proceedToNextController) { 
     // yes, correct login now perform the segue to the controller 
     [[self segmentedControl] setSelectedSegmentIndex:UISegmentedControlNoSegment]; 
     [self performSegueWithIdentifier:@"NextControllerSegueID" sender:self]; 

    } 

} 

@end 

我覺得[self performSegueWithIdentifier:@"NextControllerSegueID" sender:self];是問題,因爲自我不正確。這是錯誤發生的地方,我怎樣才能達到我期望的行爲?

回答

1

你很近,但你需要返回到委託,然後調用dismissModalViewControllerAnimated:YES。模式控制器不能自行解散,因此您需要進行登錄,回撥給委託人,並讓委託人解除模態控制器。