1

我注意到在添加带有界面生成器和笔​​尖的 viewController 时,

我不必调用 initWithNibName 来获取相关的笔尖,我可以调用 init!

知道为什么吗?

IE。

这个:

NotificationManagementController *notificationView = [[NotificationManagementController alloc] initWithNibName:@"NotificationManagementController" bundle:nil andCurrentNotifications:nil];

和这个:

NotificationManagementController *notificationView = [[NotificationManagementController alloc] init];

两者似乎可以互换......

因此,如果我然后调用这些代码行:

notificationView.delegate = self;
notificationView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:notificationView animated:YES completion:NULL];

我看到笔尖的所有变化。

4

1 回答 1

2
NotificationManagementController *notificationView = [[NotificationManagementController alloc] initWithNibName:@"NotificationManagementController" bundle:nil andCurrentNotifications:nil];

根本没有必要,甚至被一些人(包括我)不赞成。

NotificationManagementController *notificationView = [[NotificationManagementController alloc] init];

更干净(更安全),因为它隐藏了实现细节,但会initWithNibName:在幕后有效地调用。

我喜欢这样想:

- (id)init 
{
    self = [[NotificationManagementController alloc] initWithNibName:@"NotificationManagementController" bundle:nil andCurrentNotifications:nil];
    if (self)
    {
        // Initialization
    }
    return self;
}
于 2013-08-04T18:25:44.547 回答