在iOS的目标c中创建一个模态窗口

时间:2022-05-01 07:15:49

I have to create a static library for iphone which provides a interface Login. Login prompts a window and asks username and password.

我必须为iphone创建一个静态库,它提供了一个登录界面。登录会提示窗口并询问用户名和密码。

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.

我想创建一个模态窗口。因为界面不接受任何参数。我必须创建一个独立的窗口,并在其上放置文本框和登录按钮。 Plz建议我这样做。

Thanks...

4 个解决方案

#1


3  

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.

请注意,我在我的示例中使用了类方法。这是最整洁的,因为你要求它做的是从现有的视图控制器启动一个模态。这种结构在DSActivityView中有很好的效果(参见:http://www.dejal.com/blog/development)。这是一个用于在顶部任何其他视图上显示模态加载屏幕的库。

Alternatively you may want to make it an instance method depending on your needs.

或者,您可能希望根据需要将其设为实例方法。

#2


2  

You want a modal view. All UIViewControllers are able to present a modal view by using the following method:

你想要一个模态视图。所有UIViewControllers都能够使用以下方法呈现模态视图:

[self presentModalViewController:yourViewController animated:YES];

Check the Apple reference guides for more information and samples.

查看Apple参考指南以获取更多信息和样本。

#3


1  

present it with:

用它来表达:

  // to change the style of presentation
 viewController.modalPresentationStyle = UIModalPresentationStyle//....;
 //to change the transition
 viewController.modalTransitionStyle = UIModalTransitionStyle//...;
[self presentModalViewController:viewController animated:YES];

#4


0  

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

您可以创建一个使用NSRunLoop玩游戏的“模态窗口”,但我不推荐它。这很容易出错,而且不是“可可方式”。

I suggest you implement it the usual way, non modal with a delegate or block to inform the result.

我建议你以通常的方式实现它,非模态与委托或块来通知结果。

#1


3  

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.

请注意,我在我的示例中使用了类方法。这是最整洁的,因为你要求它做的是从现有的视图控制器启动一个模态。这种结构在DSActivityView中有很好的效果(参见:http://www.dejal.com/blog/development)。这是一个用于在顶部任何其他视图上显示模态加载屏幕的库。

Alternatively you may want to make it an instance method depending on your needs.

或者,您可能希望根据需要将其设为实例方法。

#2


2  

You want a modal view. All UIViewControllers are able to present a modal view by using the following method:

你想要一个模态视图。所有UIViewControllers都能够使用以下方法呈现模态视图:

[self presentModalViewController:yourViewController animated:YES];

Check the Apple reference guides for more information and samples.

查看Apple参考指南以获取更多信息和样本。

#3


1  

present it with:

用它来表达:

  // to change the style of presentation
 viewController.modalPresentationStyle = UIModalPresentationStyle//....;
 //to change the transition
 viewController.modalTransitionStyle = UIModalTransitionStyle//...;
[self presentModalViewController:viewController animated:YES];

#4


0  

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

您可以创建一个使用NSRunLoop玩游戏的“模态窗口”,但我不推荐它。这很容易出错,而且不是“可可方式”。

I suggest you implement it the usual way, non modal with a delegate or block to inform the result.

我建议你以通常的方式实现它,非模态与委托或块来通知结果。