所以我有一个UITabBarController应用程序,我想显示一个登录页面,所以我做了:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDidLogin:) name:UserDidLoginNotification object:nil];
LoginViewController* loginViewController = [[LoginViewController alloc] init];
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];
[self.tabBarController.selectedViewController presentModalViewController:loginViewController animated:NO];
[loginViewController release];
Run Code Online (Sandbox Code Playgroud)
在我的LoginViewController里面,我还可以显示另一个modalViewController:
- (void) twitterLogin: (UIViewController *) askingView
{
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: _twitter delegate: self];
if (controller) {
self.askingView = askingView;
[askingView presentModalViewController: controller animated: YES];
}
}
Run Code Online (Sandbox Code Playgroud)
我有以下方法,其中askView是LoginViewController,当我想解雇这个我做:
[self.askingView dismissModalViewControllerAnimated:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:UserDidLoginNotification object:nil];
Run Code Online (Sandbox Code Playgroud)
但是,这并没有忽略LoginViewController并显示UITabBarController视图..它只是解除了我从LoginvVIewController显示的modalViewController.我在这做错了什么?我也收到以下错误:
attempt to dismiss modal view controller whose view does not currently appear. self = <LoginViewController: 0x2aff70> modalViewController = <SA_OAuthTwitterController: 0x2d2a80>
2011-09-16 …Run Code Online (Sandbox Code Playgroud) 我正在调整现有的iPhone应用程序以在iPad上运行.在iPhone版本中,当用户点击工具栏按钮,我将提出一个模式视图控制器具有modalTransitionStyle的UIModalTransitionStyleFlipHorizontal,它做了一个非常好的"牌翻转"动画.
iPad界面基于拆分视图(MGSplitViewController实际上).工具栏按钮位于详细信息窗格上,因此当我呈现模态视图控制器时,它占据整个屏幕并且翻转过渡毫无意义.
为了获得正确的用户交互,我希望模态控制器只在详细视图控制器上显示和翻转,使主视图控制器保持原样.
有没有办法做到这一点?
uiviewcontroller ipad uisplitviewcontroller modalviewcontroller ios
基本上我有一个在app启动时加载的viewController.在那个VC中,根据是否有userdata,我使用登录来提供ModalView.用户登录后,我可以解除modalView,但我想在开启器上调用一个方法,然后用数据填充表.
我认为从modalView我可以做类似的事情
[self.parentViewController loadInitialData];
[self.dismissModalViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)
但这不起作用..
有什么建议?
iphone objective-c uiviewcontroller ipad modalviewcontroller
我试图找到释放模态视图控制器的正确方法.
基本上,我有视图控制器,按下按钮后显示模态视图(全屏).
TipViewController * tipViewController = [[TipViewController alloc] init];
tipViewController.delegate = self;
[self presentModalViewController:tipViewController animated:YES];
Run Code Online (Sandbox Code Playgroud)
然后,在模态视图中应该被解雇时我打电话给:
[self.delegate didDismissModalView];
Run Code Online (Sandbox Code Playgroud)
最后,父控制器的didDissmissModalView方法如下:
- (void)didDismissModalView
{
// dismiss the modal view controller
[self dismissModalViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)
(我使用ModalViewControllerDelegate协议,这需要实现该方法).
首先我认为我应该在父控制器的dealloc方法中释放tipViewController:
- (void)dealloc
{
[tipViewController release];
}
Run Code Online (Sandbox Code Playgroud)
但后来我看到,它可能是错误的方式,因为模态视图控制器可能会在父控制器关闭之前多次呈现和解除,并且每次它将被分配但最终只被释放一次.
那么也许我应该在呈现之后发布tipViewController?
TipViewController * tipViewController = [[TipViewController alloc] init];
tipViewController.delegate = self;
[self presentModalViewController:tipViewController animated:YES];
[tipViewController release];
Run Code Online (Sandbox Code Playgroud)
我可以这样做,虽然现在显示模态视图?
或许我应该以这种方式发布模态视图:
- (void)didDismissModalView
{
// dismiss the modal view controller
[self dismissModalViewControllerAnimated:YES];
[self.modalViewController release];
}
Run Code Online (Sandbox Code Playgroud)
假设self.modalViewController现在与tipViewController相同?
我有一个UIAlertView,它有"OK"和"Cancel"按钮.我想在OK按下按钮时显示模态视图控制器.这是我到目前为止所做的:
(void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex方法.在上面的方法中,当buttonIndex == 0我试图做一些事情的效果:
if (buttonIndex == 0)
{
ModalViewController *mdvc = [[[ModalViewController alloc] initWithNibName:nil bundle:nil] autorelease];
[self presentModalViewController:mdvc animated:YES];
}
Run Code Online (Sandbox Code Playgroud)事实证明,模态视图并不存在.我尝试了很多其他的方法,但它们只是让它变得复杂,让我创造了许多不必要的变量.必须有一个更简单的方法.
一些额外信息:
在我的应用程序中,我有一个操作表,其中一个按钮以模态方式打开TWTweetComposeViewController.在iPhone模拟器上,推特作曲家的取消按钮工作正常,并解散视图.但是,在iPad模拟器上,取消按钮不起作用,并且推特作曲家视图仍保留在屏幕上.它甚至更奇怪,因为在按下取消按钮后,键盘缩回并且底层视图变为活动状态.它表现得好像视图已经被解散但它仍然存在.
用户按下操作按钮时使用的代码是:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:@"Open in Safari"]){
[[UIApplication sharedApplication] openURL:[self.webView.request URL]];
}else if ([buttonTitle isEqualToString:@"Twitter"]){
if ([TWTweetComposeViewController canSendTweet]){
TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init];
[tweetSheet addURL:[self.webView.request URL]];
tweetSheet.completionHandler = ^(TWTweetComposeViewControllerResult result){
if (result == TWTweetComposeViewControllerResultCancelled){
[self dismissModalViewControllerAnimated:YES];
}
};
[self presentModalViewController:tweetSheet animated:YES];
}else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Twitter error" message:@"You can't send a tweet right now, make sure your device has an internet connection and you have at least …Run Code Online (Sandbox Code Playgroud) 我有一个应该是模态的第一个VC(视图控制器),并且它有一个子模态VC,有时应该在第一个VC出现时立即呈现,但有时不会.因此,从根VC我想要呈现第一个VC,并且在第一个VC上呈现子模态VC.但是用户应该只看到子VC模式转换(不是第一个VC).
AFAIK第一个VC只能在viewDidAppear:之后呈现一个模态VC,所以我不知道如何使它成为可能,因为当调用viewDidAppear:时,第一个VC已经对用户可见.
不希望用户一个接一个地看到2个模态转换,而只是最后一个模态转换,即孩子的转换.
任何提示?
好的,我知道有很多关于这个主题的信息,但是我尝试的一切都不起作用.我的设置是这样的.
应用程序使用navigationController加载View A,这是一个Tableview.延迟后,我提出了一个ModalView B.在视图B上我有一个按钮,在视图B上方显示另一个模态视图C.在模态视图中CI有一个按钮来消除C.现在当我按下这个按钮时我也想要消解模态查看B将我带回我的RootView,这是提到的tableView视图A.
从模态视图CI有一个按钮,但只能使用下面的动作来解除C这需要我进入模态视图B:我想要做的是用这个按钮删除C和B,如果可能的话,将我返回给A?
-(IBAction)dismissWebView:(id)sender{
[self dismissModalViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)
我已经从上面的行动中尝试了所有这些
[self.parentViewController dismissModalViewControllerAnimated:YES];
[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES];
[adsRootView dismissModalViewControllerAnimated:YES];
[self dismissModalViewControllerAnimated:YES];
[self dismissModalViewControllerAnimated:YES];
[self.navigationController dismissModalViewControllerAnimated:YES];
[self.adsRootView dismissModalViewControllerAnimated:YES];
[[[self parentViewController] parentViewController] dismissModalViewControllerAnimated:YES];
[self.navigationController popToRootViewControllerAnimated:NO];
Run Code Online (Sandbox Code Playgroud)
除了仅解除Modal视图C之外,其中任何一个都没有做任何事情.
uiviewcontroller uinavigationcontroller modalviewcontroller presentmodalviewcontroller ios
很抱歉,如果这看起来像一个简单的问题,但每次我在google上搜索这个主题,我都能找到的是如何将数据从子视图传递到父视图,反之亦然.
基本上,我提出了一个模态视图,它位于自己的UINavigation控制器中.模态视图需要知道是否允许用户"编辑"它 - 所以我认为最简单的方法是将子视图(isEdit)上的BOOL设置为TRUE(这将得到根据正在发生的segue设置)但是因为这个模态视图是从UINavigation控制器呈现的 - 我无法从 - (void)prepareForSegue函数访问它并直接设置BOOL.我已经尝试了子类化UINav控制器,并在其中包含一个可以设置的BOOL,然后在子视图中检查,但我似乎无法从子视图访问控制器 - 我会包含我的代码,但我确定必须有一种更简单的方法来完成这项任务!
有人能够建议一种更经济的方式将这个布尔值"通过"UINavigationController传递给子视图吗?
谢谢
我有一个支持iPad和iPhone的通用应用程序。在iPad上,我支持所有方向;在iPhone上,我仅支持纵向。
我希望一个视图控制器(以模态显示)在iPhone上运行时能以设备所处的任何方向显示。我已经看到许多教程和SO帖子,建议使用-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window应用程序委托方法,这似乎可行关于旋转模态视图控制器绝对好。但是,当我在横向模式下关闭模式视图时,整个应用程序仍保持横向模式。
理想情况下,一旦取消模式视图,应用程序应回到纵向模式。
经过调查,似乎-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window在关闭视图控制器后未调用回调,而且我不知道为什么。
我在这里玩过示例应用程序,并且在关闭视图控制器时触发了回调,但我不知道为什么。我可以看到的唯一区别是我的视图层次结构要复杂得多,并且我显示的是导航控制器,而不是显式的视图控制器,但是我看不到这将如何影响回调。
有什么解决方案的想法吗?
谢谢
iphone objective-c uiinterfaceorientation modalviewcontroller ios