开发者

How to send a message over presentModalViewController to a UIViewContoller(login) that Button is pressed?

So here is my problem:

I have an AppDelegate with a navigationController:

[self.window addSubview:navigationController.view];

In there i put an presendModalViewController:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
 [[self navigationController] presentModalViewController:passwordViewController animated:YES];

}

I want an PasswordView which takes the Password and tells the UIView in the NavigationController that he can begin his work with catching information from the internet, with a nice MBProgressHUD Loading View.

I tried to build up an Delegate but it does´t work because the instance of my UIView is build up in the Navigation controller开发者_开发百科.

I there a way to tell my UIView which is in my NavigationController that Password was given and back that the Password was right und say back with:

[self.parentViewController dismissModalViewControllerAnimated:YES];

to remove this View?

There is an App named iOutbank which has what I want to assume...


Add a delegate to your view controller class that is invoked when a valid password has been entered. Something like this in your login view controller would work:

@protocol LoginDelegate
    - (void)loginSucceeded;
@end


@interface LoginViewController : UIViewController 
{
    id<LoginDelegate> delegate;
}

}

Next, set the delegate of your password view controller to be the app view controller class. To do this your app delegate class needs to implement the protocol you've defined for your login delegate, so in the app delegate header and implementation files:

@interface MyAppDelegate : NSObject <LoginDelegate>
{
    // App delegate interface stuff
}

@implementation MyAppDelegate
{
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Create myLoginViewController          

       [myLoginViewController setDelegate:self];

       // Display login view controller           
    }

    - (void)loginSucceeded
    {
        // Dismiss login view controller
        // Do other stuff
    }

}

When your app delegate class gets notified that the password has been entered, then you can dismiss the password view controller and do whatever it is you want to do next.


@Tim Dean, thank you very much you helped me to help myself and think about my problem. So this is how i ended up doing it:

I made an instance of my PasswordView in My tableView:

     - (void)viewDidLoad
{

self.passwordView = [[PasswordViewController alloc]init];
[passwordView setPasswordViewDelegate:self];

[self.navigationController presentModalViewController:self.passwordView animated:YES];
}

Put in there my Delegate:

@interface TableView : UITableViewController <PasswordViewDelegate>
{


PasswordViewController *passwordView;

}

And get my Delegate method from my PasswordView:

-(void)loginPressed
{
NSLog(@"Login Pressed");
[self.parentViewController dismissModalViewControllerAnimated:YES];



 }

And now I can use my logic of my TableViewClass.

I love stack overflow!

Greetings and I hope there is somebody I shall helped with my solved problem, I'm going to sleep now....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜