Tag: uiviewcontroller

事件willAnimateRotationToInterfaceOrientation不调用

我有几个UIViewController在应用程序上。 但是只有其中的一个会调用willAnimateRotationToInterfaceOrientation事件。 如何使willAnimateRotationToInterfaceOrientation适用于所有可见视图?

IOS:移回两个视图

我一直坚持这个问题一段时间,找不到任何有用的信息,如何做到这一点.. 我有一个基本视图(视图1),我可以在tableview中select项目。 在项目“页面”(视图2)时,我可以select编辑该项目,触发模态视图(视图3)。 在这个模式下,我可以select删除这个项目。 如果用户按下该button并确认他们想要删除该项目,我想发送应用程序回查看1 .. 我已经尝试了一些不同的东西( popToViewController , pushViewController , dismissViewController等),但我不能得到任何工作。 如果我得到模式closures,查看2不closures。 有时甚至模态也不会消失。 基本视图是一个UITableViewController ,另外两个是UIViewControllers ,而我正在使用storyboard 。

在另一个类中设置标签文本

在我的视图控制器中,我在这里创build一个标签。 在另一个视图控制器中,我创build了第一个视图控制器的一个实例。 在这里,我尝试设置标签的文本属性。 但它不起作用。 我检查了一遍又一遍的代码,找不到任何遗漏。 我尝试以编程方式创build标签以及使用界面生成器。 仍然不能设置标签的文本属性。 有什么理由呢? 我在中创build标签 – (void)viewDidLoad { myLabel = [[UILabel alloc]init]; [myLabel setText:@"Hi"]; [myLabel1 setText:@"Hello"]; [myLabel setFrame:CGRectMake(105, 130, 120, 30)]; [myLabel setBackgroundColor:[UIColor clearColor]]; [myLabel setTextColor:[UIColor whiteColor]]; [myLabel setTextAlignment:UITextAlignmentCenter]; [myLabel setAdjustsFontSizeToFitWidth:YES]; [self.view addSubview:myLabel]; [myLabel release]; } 在我的第一个视图控制器 MySecondViewcontroller *showMyViewcontroller = [[ MySecondViewcontroller alloc]initWithNibName:@"MySecondViewcontroller" bundle:nil];; showMyViewcontroller.myLabel = @"I cant set the text"; […]

不调用呈现视图控制器的dismissModalViewControllerAnimated:方法的模式视图控制器

在我的模式视图控制器,我有一个button处理方法,其中包括 [self dismissModalViewControllerAnimated: YES]; 在呈现视图控制器我重写dismissModalViewControllerAnimated:如下所示: -(void) dismissModalViewControllerAnimated: (BOOL)animated { NSLog(@"dismiss"); [super dismissModalViewControllerAnimated: animated]; } 当button被触摸时,button处理方法被调用,但dismissModalViewControllerAnimated:覆盖似乎并没有被调用:NSLog(@“dismiss”); 语句不被调用,并且方法内部的断点不会被打中。 我试过了 [[self presentingViewController] dismissModalViewControllerAnimated: YES]; 但是这也不起作用。 但是,模态视图控制器不会被解雇。 任何想法可能会出错?

在保持TabBar的同时在AppDelagate中打开ViewController

在我的Xcode项目中,当用户点击通知时,我想先将它们发送到tabBar中的某个项目,然后我想实例化一个视图控制器并将对象发送到该视图控制器。 我有代码将它们发送到我想要的tabBar,但我不知道如何将它们实例化到视图控制器,同时保持TabBar和导航栏连接到视图控制器。 所有的答案都需要你改变根视图控制器,这使得当视图控制器被调用时,我失去了与我的tabBar和导航栏的连接。 一个真实生活的例子:用户收到Instagram通知说:“约翰开始关注你” – >用户点击通知 – > Instagram打开并显示通知选项卡 – >快速发送用户到“约翰”configuration文件,当用户按下后退button,它将它们发送回通知选项卡 应该知道:为什么我要去某个选项卡首先是得到该选项卡的导航控制器,因为我要去的视图控制器没有。 这里是我的工作代码发送用户到“通知”选项卡(我添加了评论像Instagram示例更好的理解): if let tabbarController = self.window!.rootViewController as? UITabBarController { tabbarController.selectedViewController = tabbarController.viewControllers?[3] //goes to notifications tab if type == "follow" { //someone started following current user //send to user's profile and send the user's id so the app can find all the information […]

将两个XIB连接到一个ViewController

我在所有的基础上,想要有一个iPhone的视图,一个iPad。 不过,我想为它们使用相同的视图控制器,因为它们是相同的东西,只是为每个设备进行了优化。 我知道这是可能的,因为它是一个通用的应用程序,通用项目的默认视图包含一个iPhone主视图和一个iPad主视图。 但是,他们自动实现,所以我不知道如何复制这个。 所以,这个问题的答案是:你如何将两个xib连接到一个viewcontroller? 谢谢, 可靠的人

在UIViewController被popup之后,MKMapView autorelease不会调用dealloc

我在类A中有以下代码: UIViewController *vc = [self viewControllerForItem:item]; 在我的应用程序委托viewControllerForItem方法返回一个UIViewController基于我的项目即 vc = [[[MyCustomViewController alloc] init] autorelease]; return vc; 然后我推视图控制器: [self.navigationController pushViewController:vc animated:YES]; 这个VC我试图推动一个MKMapView,我在dealloc方法插入一个日志语句,看看是否被调用。 在我的记忆中,增长速度非常快。 但是,当我推入VC后添加下面的代码: [vc release]; 我的MKMapView类调用dealloc方法。 当然,如果MKMapView类是我的应用程序委托返回的唯一类(或者我可以检查VC的类是否是我的MKMapView类),这将是一个简单的解决scheme。 不过,我想解决这个根本问题。 为什么在我的视图控制器上设置autorelease时,dealloc没有被调用? 即使在该vc上使用autorelease,我怎么可能将[vc release]添加到视图控制器? 谢谢 编辑: 这里有一些额外的信息。 我有我的应用程序委托viewControllerForItem类。 我将自动释放的对象返回到我的其他pipe理器类,然后我推视图控制器。 当我返回一个自动释放对象时,保留计数是否被搞乱了,然后把它推到其他类中? 这是当我推VC和mkmapview的didDissappear被调用时的backtrace / callstack: pushVC: ( 0 NewHampshire 0x00254cdf -[CustomViewController navigateToRowId:withLinkBehavior:animated:] + 2111 1 NewHampshire 0x002534c9 -[CustomViewController webView:shouldStartLoadWithRequest:navigationType:] + 841 […]

从详细视图中禁用/启用后退button

我如何禁用从详细视图控制器的后退button?

在Swift中用UIViewController的自定义init,在storyboard中设置界面

我有问题为UIViewController的子类编写自定义的init,基本上我想通过viewController的init方法传递依赖,而不是像viewControllerB.property = value直接设置属性 所以我为我的viewController做了一个自定义的init,并调用超级指定的init init(meme: Meme?) { self.meme = meme super.init(nibName: nil, bundle: nil) } 视图控制器界面驻留在故事板中,我也使自定义类的界面成为我的视图控制器。 即使你没有在这个方法中做任何事情,Swift也需要调用这个init方法。 否则,编译器会抱怨… required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } 问题是,当我尝试使用MyViewController(meme: meme)调用我的自定义init时,它并没有在我的viewController中初始化属性… 我试图debugging,我发现在我的viewController, init(coder aDecoder: NSCoder)先调用,然后我的自定义的init后来调用。 但是这两个init方法返回不同的self内存地址。 我怀疑我的viewController初始化有什么问题,它总是会返回self与init?(coder aDecoder: NSCoder) ,没有实现。 有谁知道如何正确地为您的viewController自定义初始化? 注意:我的viewController的界面是在storyboard中设置的 这里是我的viewController代码: class MemeDetailVC : UIViewController { var meme : Meme! @IBOutlet weak var editedImage: UIImageView! // […]

使用自定义animation时,会在iOS9上忽略edgesForExtendedLayout

当使用UIViewControllerAnimatedTransitioning实现自定义animation时,iOS9似乎忽略了目标视图控制器的edgesForExtendedLayout ,因此内容会在导航栏下方结束。 任何想法为什么发生这种情况? 我已经在https://github.com/nmarkovic04/CustomAnimationTest举办了一个例子。 在8.4和9.1上运行它显示了不同之处,但是你很可能会尝试任何其他的8.x和9.x版本。 运行在Xcode 7,Swift 2.0上。