- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我将 UIViewController
子类化为 STViewController
并注意到从 STViewController
继承的类有它们的 viewDidLoad
方法被重复调用.最终导致应用程序崩溃。 STViewController
在这一点上基本上是一个空白的实现。我正在子类化,如下所示:
#import "STViewController.h"
@interface WelcomeViewController : STViewController {
STViewController.h
#import <UIKit/UIKit.h>
@interface STViewController : UIViewController
{
}
@end
STViewController.m
#import "STViewController.h"
@implementation STViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)loadView
{
// Implement loadView to create a view hierarchy programmatically, without using a nib.
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
来自 WelcomeViewController.m 的 viewDidLoad()
- (void)viewDidLoad
{
[super viewDidLoad];
// hide the buttons
[[self signUp] setHidden: YES];
[[self logIn] setHidden: YES];
}
最佳答案
您正在覆盖 loadView
,但您的实现是空的,并且您没有分配 View 。删除 loadView
覆盖。
来自 UIViewController Class Reference (强调我的):
You should never call this method directly. The view controller calls this method when the view property is requested but is currently nil. If you create your views manually, you must override this method and use it to create your views. If you use Interface Builder to create your views and initialize the view controller—that is, you initialize the view using the initWithNibName:bundle: method, set the nibName and nibBundle properties directly, or create both your views and view controller in Interface Builder—then you must not override this method.
The default implementation of this method looks for valid nib information and uses that information to load the associated nib file. If no nib information is specified, the default implementation creates a plain UIView object and makes it the main view.
If you override this method in order to create your views manually, you should do so and assign the root view of your hierarchy to the view property. (The views you create should be unique instances and should not be shared with any other view controller object.) Your custom implementation of this method should not call super.
关于objective-c - 子类化 UIViewController,viewDidLoad 反复调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8866573/
我有一个小心理障碍:我有一个 html 中的 javascript 函数,可以在按下某个键时写入键码。我已经将它连接到一个函数,该函数可以准确地告诉我按下了什么字符和键码(不包括在内)。 我的问题是如
我上网已经有一段时间了,现在正试图解决这个问题。可以找到正在发生的事情的视频: https://i.gyazo.com/59fc489b6099b513c41aedeed482b8d2.mp4 $(d
我有一个 Python 程序,其中一个函数导入另一个脚本并运行它。但是脚本仅在第一次函数被调用时运行。 def Open_Generator(事件): 导入密码生成器 有什么建议吗? *该函数在 tk
我正在尝试在 git 中创建两个包含二进制文件的分支 - 一个“开发”分支和一个“稳定”分支。在我想将它们“发布”到稳定分支之前,开发分支可以对这些文件进行一些更改(并且稳定分支已重命名这些文件,以防
我在 IBM BlueMix 中的 Node Red 应用程序反复崩溃 - 每小时一次 - 除了“exited with status: 1.”之外没有任何真正的错误消息 如何解决此问题? 是否有来自
我是一名优秀的程序员,十分优秀!