creating a modal window in objective c for iOS
I have to create a static library for iphone which provides a interface Login. Login prompts a window and asks username and password.
I wanted to create a modal window. As the interface doesnt take any arguments. I have to create a independent window and put text boxes and login button on it. Plz suggest me way to do this.
Thanks...开发者_JS百科
A flexible way to do this is to make the calling code pass in the parent view controller. Something like this would work:
[CustomLoginManagerClass shownLoginOver:self.viewController otherStuff:_____];
and then assuming your method definition is something like this, you can easily launch your modal from there.
+ (void)shownLoginOver:(UIViewController*)viewController otherStuff:(id)stuff
{
[self presentModalViewController:viewController animated:YES];
}
Note that I have used a class method for this in my example. This is neater since all you are asking it to do is launch a modal from an existing view controller. This structure is used to good effect in DSActivityView (see: http://www.dejal.com/blog/development). This is a library for displaying modal loading screens over the top any other view.
Alternatively you may want to make it an instance method depending on your needs.
You want a modal view. All UIViewControllers
are able to present a modal view by using the following method:
[self presentModalViewController:yourViewController animated:YES];
Check the Apple reference guides for more information and samples.
present it with:
// to change the style of presentation
viewController.modalPresentationStyle = UIModalPresentationStyle//....;
//to change the transition
viewController.modalTransitionStyle = UIModalTransitionStyle//...;
[self presentModalViewController:viewController animated:YES];
You can create a "modal window" playing games with the NSRunLoop
, but I don't recommend it. It's very error prone and it's not the "Cocoa way".
I suggest you implement it the usual way, non modal with a delegate or block to inform the result.
精彩评论