creating a modal window in objective c for iOS

15,371

Solution 1

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.

Solution 2

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.

Solution 3

present it with:

  // to change the style of presentation
 viewController.modalPresentationStyle = UIModalPresentationStyle//....;
 //to change the transition
 viewController.modalTransitionStyle = UIModalTransitionStyle//...;
[self presentModalViewController:viewController animated:YES];
Share:
15,371
user799473
Author by

user799473

Updated on June 04, 2022

Comments

  • user799473
    user799473 almost 2 years

    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...