Tag: uiviewcontroller

UIViewController的子类所需的初始化器

我一直在试图按照关于创build一个容器视图控制器的教程。 它在Objective-C中。 我想把它转换成Swift。 我在这里发现了一些相同的问题,但是我没有从中得到太多的答案。 这是代码。 import UIKit class ContainerViewController: UIViewController { // Class "ContainerViewController" has no initializers – That I know why. // 'required' initializer 'init(coder:)' must be provided by a subclass of UIViewController var currentDetailViewController: UIViewController override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } } 我已经尝试了这两个错误说,但仍然无法正常工作。

animationiOS与声音文件

我有一些需要在非常特定的时间出现在屏幕上的animation,这些animation存储在SQLite数据库中。 我打算做的是使用nstimer来保持时间,并在达到特定时间时popupanimation。 我想使用NSTimer计数声音文件和animation的持续时间,然后当达到某些点popup一个屏幕上的animation。 问题是设置的时间是这样的55.715000秒,所以非常准确,这些都需要与animation播放的音轨同步。 首先,这甚至是可能的,其次,我怎样才能比较这样的具体时间,我似乎面临的问题是代码运行不够快,时间跳跃超过.001秒。 我没有openGLES或Cocos2d的知识,学习这些在时间尺度上是不可行的。

UIViewController可见的callback

我正在开发一个iOS应用程序,当我有Internet连接和其他的时候需要做一些东西,当我没有。 如果我没有在某个时候,我会显示一条消息给用户给我互联网和回来。 问题是如何检测以下情况: 用户按两次主页button,进入多任务处理,设置并连接到互联网 用户回来多任务到我的应用程序,但不按任何东西 我知道我会得到AppDelegatecallback: – (void)applicationDidEnterBackground:(UIApplication *)application – (void) applicationDidBecomeActive:(UIApplication *)application 但代码(它不是由我开始)这是非常大的,我不想处理那里的UIViewController需要,如果有任何替代。 我的UIViewController的 – (无效)viewDidAppear:(布尔)animation,当用户回来时不会调用它。 这个断点不是肯定的! 任何有用的想法,除了在AppDelegate?

closures当前视图控制器中以前的模式视图控制器

我目前有3个ViewController: LoginViewController , SignUpViewController和MainViewController 。 当用户打开应用程序时,将显示LoginViewController 。 如果用户第一次使用该应用程序,那么他们将不得不注册,“注册”button在LoginViewController 。 “注册”button将popupSignUpViewController 。 一旦用户完成注册。 MainViewController将会出现。 我正在试图做的是。 在MainViewController会有一个“注销”button。 当用户按下它时, MainViewController应该被解除, LoginViewController应该在那里。 用户不应该SignUpViewController看到SignUpViewController 。 这是我所尝试的: 1)closuresSignUpViewController并在“注册”button中显示MainViewController : – (void) signUpClicked { MainViewController *mainViewController = [viewController.storyboard instantiateViewControllerWithIdentifier:@"MainViewController"]; [viewController presentViewController:mainViewController animated:YES completion:^{ [viewController dismissViewControllerAnimated:NO completion:^{ }]; }]; } 2)当MainViewController加载时,closuresSignUpViewController – (void)viewDidLoad { [super viewDidLoad]; SignUpViewController *signUpViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SignUpViewController"]; [signUpViewController dismissViewControllerAnimated:NO […]

以编程方式创build和呈现模态视图控制器

我正在试图以编程方式声明从使用故事板启动的视图控制器的模式视图控制器。 我希望能看到一个空白的视图,但是我只能看到第一个控制器的webview。 – (void)viewDidLoad { [super viewDidLoad]; NSString *fullURL = @"http://google.com"; NSURL *url = [NSURL URLWithString:fullURL]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; _viewWeb.delegate=self; [_viewWeb loadRequest:requestObj]; modalViewController=[[UIViewController alloc] init]; [self presentViewController:modalViewController animated:YES completion:nil]; }

未调用UIViewController-dealloc方法

我正在使用自动引用计数。 我有一个自定义的UIViewController子类,每当我调用-presentViewController: animated:completion:或从-presentViewController: animated:completion:视图中删除它的视图我想NSLog东西像“我dealloced”,所以我知道视图控制器已被成功删除。 我在我的视图控制器中实现了-dealloc方法。 然而,我开始了一个testing项目,我刚刚有两个UIViewController实例(没有保留周期)和-dealloc不调用或者当我推动第二个UIViewController模态或当我删除超级视图或当我从父视图控制器中删除它。 我错过了什么吗? 在我原来的项目(不是testing案例)中,乐器向我展示了那些控制器留下的内存空间,我无法摆脱。

Swift自定义UITableViewCell委托给UIViewController只有一个协议的作品

在应用程序中,我有我的UIViewController符合的自定义协议。 我有一个自定义的tableViewCell类,并在那里有UIImageView和UITextView。 出队后,我将单元格的委托设置为UIViewController。 然而,只有一个自定义协议使callback(imagepicker协议)。 protocol customProtocol1{ func pickImage(myInt: Int) } protocol customProtocol2{ func protocol2 (myInt: Int) } class controller1: UIViewController, UITableViewDelegate, customProtocol1, customProtocol2 { func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } func tableView(tableView: UITableView, numberOfRowsInSection section:Int) -> Int { return 3 } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell […]

强制设备旋转时+ attemptRotationToDeviceOrientation失败

根据这里的UIViewController文档, https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/clm/UIViewController/attemptRotationToDeviceOrientation 使用[UIViewController attemptRotationToDeviceOrientation]强制系统尝试将界面旋转到新的方向。 我试图强制从纵向到横向的界面旋转: 在尝试旋转之前设置forceLandscape标志 调用[UIViewController attemptRotationToDeviceOrientation] 在我的视图控制器中实现-supportedInterfaceOrientations并检查标志以更改支持的方向,例如 这迫使-supportedInterfaceOrientations再次被调用,看起来像 – (NSUInteger)supportedInterfaceOrientations { return self.forceLandscape ? UIInterfaceOrientationMaskLandscapeLeft : UIInterfaceOrientationMaskPortrait; } 即使正在调用-supportedInterfaceOrientations并返回新的方向,接口也不会旋转。 我已经确认该项目允许所有的方向,并且这个视图控制器是窗口的根视图控制器。 有没有其他人遇到这个问题,并find一个解决scheme? 我知道所有的窍门,以解决这个问题(提交和解雇模态等),但我希望有一个干净的解决scheme,如果可能的话。 我已经在iOS 6和7上validation了这个问题。 以下是完整的代码重现: @interface ALTViewController () @property (nonatomic, assign) BOOL forceLandscape; @end @implementation ALTViewController – (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.forceLandscape = NO; […]

iOS Swift:UIPageViewController – 以编程方式翻页

我有一个UIPageViewController,当我们向左或向右滑动页面时,它工作正常。 class ViewController: UIViewController, UIPageViewControllerDataSource { … } 现在我打算在页面上提供Previous / Nextbutton,这样就可以通过点击这些button来打开页面。 我如何触发滑动左/右行为或编程翻页? 注意这是SWIFT语言的问题,而不是Objective-C。

dismissViewControllerAnimated在块内不起作用

在显示UIAlertController后,我尝试closures一个UIViewController 。 这是我的代码: UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Accept" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [self dismissViewControllerAnimated:YES completion:nil]; }]; [alertController addAction:okAction]; [self presentViewController:alertController animated:YES completion:^{}]; 但是, self永远不会被解雇。 有人知道如何解决这个问题? UPDATE 如果我设置[self dismissViewControllerAnimated:YES completion:nil]; 在块之外,它的工作。