开发者

Why is there such a long delay when pushing this UIViewController?

I am pushing a simple UIViewController onto a navigation controller, and there is about a 1 second delay before the push animation begins. This is after a fresh build. After loading it one time, it no longer has the delay.

The root view controller has 3 other table cells that push different view controllers onto the stack, and none of them have the same type of delay. Additionally, this VC in question is the simplest (in terms of the amount of code) of the 4.

I push all the VCs using the technique:

    if (!editExerciseViewController) {
        editExerciseViewController = [[EditExerciseViewController alloc] initWithStyle:UITableViewStyleGrouped];
    }

Here is the code of the ViewController in question:

#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 = CGRe开发者_如何学GoctMake(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

Is there something in this code that is causing this delay?

I am testing it on a iPhone 3GS.


The problem is with the Keyboard. The first time the keyboard is loaded on older devices it is slowwwww. You can preload the Keyboard in your app. Here are some pointers.

Link

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜