为什么在按下此UIViewController时会有这么长的延迟?

问题描述

| 我正在将一个简单的UIViewController推送到导航控制器上,推送动画开始之前大约有1秒的延迟。这是在重新构建之后。加载一次后,它不再具有延迟。 根视图控制器具有其他3个表单元,这些表单元将不同的视图控制器推入堆栈,并且它们都没有相同类型的延迟。此外,该VC是4中最简单的(就代码量而言)。 我使用该技术推送所有VC:
    if (!editExerciseViewController) {
        editExerciseViewController = [[EditExerciseViewController alloc] initWithStyle:UITableViewStyleGrouped];
    }
这是有问题的ViewController的代码
#import \"EditExerciseViewController.h\"

@implementation EditExerciseViewController
@synthesize exerciseField;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        [[self navigationItem] setTitle:@\"Exercise\"];   
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

#pragma mark - View lifecycle

- (BOOL)shouldAutorotatetoInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;

    CGFloat viewWidth;
    viewWidth = 130.0f;
    CGRect frame = CGRectMake(0.0f,0.0f,viewWidth,21.0f);

    if ([indexPath row] == 0) {
        // If Exercise cell
        if (cell == nil)
        {
            cell = [[UITableViewCell alloc] initWithFrame:CGRectZero];
        }

        cell.textLabel.text = NSLocalizedString(@\"Exercise\",nil);
        exerciseField = [[UITextField alloc] initWithFrame:frame];
        [exerciseField setKeyboardType:UIKeyboardTypeNumberPad];
        [exerciseField setTextAlignment:UITextAlignmentRight];
        [exerciseField setClearsOnBeginEditing:YES];
        [exerciseField setPlaceholder:NSLocalizedString(@\"calories\",nil)];
        [exerciseField setTextColor:[UIColor colorWithRed:0.20f green:0.31f blue:0.52f alpha:1.0f]];

        [cell setAccessoryView:exerciseField];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        [exerciseField becomeFirstResponder];

    }

    return cell;
}

@end
这段代码中是否有引起延迟的内容? 我正在iPhone 3GS上对其进行测试。     

解决方法

        问题出在键盘上。第一次在较旧的设备上加载键盘时速度很慢。您可以在应用程序中预加载键盘。这里有一些指针。 链接