Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios PresentViewController需要很多时间_Ios_Objective C_Cocoa Touch_Uinavigationcontroller - Fatal编程技术网

Ios PresentViewController需要很多时间

Ios PresentViewController需要很多时间,ios,objective-c,cocoa-touch,uinavigationcontroller,Ios,Objective C,Cocoa Touch,Uinavigationcontroller,我有一个非常奇怪的情况:由presentViewController调用的视图控制器需要花费很多时间来加载。我的意思是,准备阶段需要很多时间,尽管整个动画表演很快。从呈现的控制器返回到上一个控制器是可以的 我有什么线索 首先,我在First视图中将出现的下一个视图控制器中准备好了: METAddEventViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"addEvent

我有一个非常奇怪的情况:由
presentViewController
调用的视图控制器需要花费很多时间来加载。我的意思是,准备阶段需要很多时间,尽管整个动画表演很快。从呈现的控制器返回到上一个控制器是可以的

我有什么线索

首先,我在First
视图中将出现的下一个视图控制器中准备好了:

METAddEventViewController *controller = [self.storyboard 
instantiateViewControllerWithIdentifier:@"addEventView"];

self.nextController =
[[UINavigationController alloc] initWithRootViewController:controller];
- (void)viewDidLoad
{
self.appointMeetingButton.enabled = NO;

self.title = @"Create Meeting";

self.commentaryView.delegate = self;

[super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[self navigationController] setNavigationBarHidden:NO animated:NO];
self.commentaryView.text = @"Enter comment for the meeting if needed";
self.commentaryViewFilled = NO;
self.commentaryView.textColor = [UIColor lightGrayColor];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(updateSelectedPersonCalled:)
                                             name:@"updateSelectedPersonLabel"
                                           object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(updateSelectedPersonCalled:)
                                             name:@"updateSelectedLocationLabel"
                                           object:nil];


[self.datePicker addTarget:self action:@selector(meetingAppointable) forControlEvents:UIControlEventValueChanged];

}
其中,
self.nextController
是非原子且强的

因此,我调用下一个控制器的方法非常简单:

- (IBAction)addMeetingButtonPressed:(id)sender {
[self.addMeetingButton setImage:[UIImage imageNamed:@"addMeeting-pressed@2x.png"] forState:UIControlStateNormal];

[self presentViewController:self.nextController animated:YES completion:^{
    NSLog(@"Completed");
}]; 
}
METAddEventViewController
只是一个
UITableViewController
,静态单元格为4:2个基本单元格,1个单元格为
UIDatePicker
,1个单元格为
UITextView

因此,我的
viewDidLoad
视图将出现

METAddEventViewController *controller = [self.storyboard 
instantiateViewControllerWithIdentifier:@"addEventView"];

self.nextController =
[[UINavigationController alloc] initWithRootViewController:controller];
- (void)viewDidLoad
{
self.appointMeetingButton.enabled = NO;

self.title = @"Create Meeting";

self.commentaryView.delegate = self;

[super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[self navigationController] setNavigationBarHidden:NO animated:NO];
self.commentaryView.text = @"Enter comment for the meeting if needed";
self.commentaryViewFilled = NO;
self.commentaryView.textColor = [UIColor lightGrayColor];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(updateSelectedPersonCalled:)
                                             name:@"updateSelectedPersonLabel"
                                           object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(updateSelectedPersonCalled:)
                                             name:@"updateSelectedLocationLabel"
                                           object:nil];


[self.datePicker addTarget:self action:@selector(meetingAppointable) forControlEvents:UIControlEventValueChanged];

}
我运行了分析,发现最耗时的操作是分配操作。尽管如此,
METAddEventController
viewDidLoad
viewwillbeen
都很好-大约10毫秒。其中大部分时间都需要配置
self.commentaryView


我能做什么?我可以提供哪些其他信息来找到解决方案?

尝试调用[self.nextController view];就在init之后。Objective-C在需要之前初始化视图,而不是在初始化之后直接初始化。这一行应该强制它立即初始化视图。@PrzemysławWrzesiński我将它添加到
controller
nextController
中,似乎将时间从2.0秒减少到1.6秒。然而,这种悬念是显而易见的,嗯,这确实是一个奇怪的问题。可能按钮函数没有在主线程中执行?请尝试:
dispatch_async(dispatch_get_main_queue(),^{[self presentViewController:self.nextController动画:YES completion:nil];})无更改。然而,我注意到它从1.6降低到1.2,当再次加载时,如Add->Go back->Add,我会说需要0.4s才能真正加载,1.2s做了一些奇怪的事情,不知道这是什么:)你能发布init方法吗?