我正在尝试为我的init
编写自定义UIViewController
方法。这是方法本身:
- (instancetype)initWithBottomViewController:(UIViewController *)bottomViewController andTopViewController:(UIViewController *)topViewController {
self = [super init];
if (self) {
self.bottomViewController = bottomViewController;
self.topViewController = topViewController;
}
return self;
}
- (void)setupBottomViewController {
/*crashes here because self.bottomViewController appears to be nil*/
[self addChildViewController:self.bottomViewController];
[self.bottomViewController.view setFrame:self.view.bounds];
[self.view addSubview:self.bottomViewController.view];
[self.bottomViewController didMoveToParentViewController:self];
}
控制台说-[__NSArrayM insertObject:AtIndex:] object cannot be nil
我在init
中调用AppDelegate.m
函数:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
BottomViewController *bottomVC = [[BottomViewController alloc] initWithNibName:@"BottomViewController" bundle:nil];
TopViewController *topVC = [[TopViewController alloc] initWithNibName:@"TopViewController" bundle:nil];
SlideMenuController *slideController = [[SlideMenuController alloc] initWithBottomViewController:bottomVC andTopViewController:topVC];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = slideController;
[self.window makeKeyAndVisible];
return YES;
}
属性self.bottomViewController
和self.topViewController
在.h
文件中声明:
@property (strong, nonatomic) UIViewController *bottomViewController;
@property (strong, nonatomic) UIViewController *topViewController;
问题在于分配给self.bottomViewController
和self.topViewController
。 bottomViewController
和topViewController
不是nil
,但是self.bottomViewController
和self.topViewController
是{{1}}。我自己弄不清楚。提前致谢!
答案 0 :(得分:0)
问题是我为class Window
{
private:
void constructor_method(int a);
void constructor_method(int a, void *b);
void constructor_method(string a);
public:
Window(int a) {
constructor_method(a);
}
Window(int a, void *b) {
constructor_method(a, b);
}
Window(string a) {
constructor_method(a);
}
Window(double a, double b)
{
if (a * b == 0.0)
{
constructor_method("ZERO");
}
else if (a * b > 100.0)
{
constructor_method((int) (a + b), x);
}
else
{
constructor_method((int) (a + b));
}
}
};
和<body>
<form id="form1" runat="server">
<div id="signature-pad" class="signature-pad">
<div class="signature-pad--body">
<canvas></canvas>
</div>
<div class="signature-pad--footer">
<div class="description">Sign above</div>
<div class="signature-pad--actions">
<div>
<button type="button" class="button clear" data-action="clear">Clear</button>
<button type="button" class="button" data-action="change-color">Change color</button>
<button type="button" class="button" data-action="undo">Undo</button>
<asp:button text="Save" runat="server" cssclass="button save" data-action="save" onclick="Save" />
</div>
<div>
<button type="button" class="button save" data-action="save-png">Save as PNG</button>
<button type="button" class="button save" data-action="save-jpg">Save as JPG</button>
<button type="button" class="button save" data-action="save-svg">Save as SVG</button>
</div>
</div>
</div>
</div>
<input type="hidden" id="hfSign" runat="server" />
</form>
<script src="js/signature_pad.umd.js"></script>
<script src="js/app.js"></script>
</body>
都实现了空的setter方法。