开发者

UITableView Poor Scroll Performance w/ UITextField in subclassed cell

开发者 https://www.devze.com 2023-03-19 20:31 出处:网络
I have bee开发者_如何转开发n working on a UITableView on iPad with UITextFields contained in cells, much like the address book edit mode.

I have bee开发者_如何转开发n working on a UITableView on iPad with UITextFields contained in cells, much like the address book edit mode.

I have subclassed UITableViewCell to make my own: FormCell and added a property of UITextField *inputField to the contentView of the cell in init. I then adjust the position of the inputField in layoutSubviews.

I have about 20 rows of these and I get bad scrolling performance. The instruments profile gives about 15fps when i am just scrolling these FormCells back and forth. In comparison, it showed 50+ fps if the cells were just regular type.

The amazing thing is when i activate one of the inputField in the cell, keyboard shows, and i am able to scroll back and forth at 40fps, which is very smooth. in comparison, address book on iPad scrolls at 58 fps when in edit mode.

Can any one advise what is going on and how I can get better performance withotu activating the inputFields in the cells?

Thank you,

here are the code for FormCell:

@implementation FormCell

@synthesize inputField;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //Initialization code
        inputField = [[UITextField alloc] init];
        inputField.font = [UIFont systemFontOfSize:20];
        inputField.minimumFontSize = 13;
        inputField.adjustsFontSizeToFitWidth = YES;

        inputField.autocapitalizationType=UITextAutocapitalizationTypeWords;
        inputField.clearButtonMode = UITextFieldViewModeWhileEditing;
        inputField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

        inputField.returnKeyType = UIReturnKeyNext;

        [self.contentView addSubview:inputField];
        self.textLabel.font = [UIFont boldSystemFontOfSize:16];
        [inputField release];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];

    NSInteger cellWidth = self.contentView.frame.size.width;
    if (self.textLabel.text) {
        self.textLabel.frame = CGRectMake(20, 10, 100, 30);
        [inputField setFrame:CGRectMake(140, 10, cellWidth-160, 30)];
    }else{
        [inputField setFrame:CGRectMake(10, 10, cellWidth-20, 30)];
    }
}

- (void)prepareForReuse{
    [super prepareForReuse];
    self.textLabel.text = nil;
    self.detailTextLabel.text = nil;
    self.inputField.text = nil;
    self.inputField.placeholder = nil;
    self.inputField.enabled = YES;
    self.inputField.hidden = NO;
    self.accessoryView = nil;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

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

And here is the code for cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *InputCellID = @"InputCell";
    TextInputCell *cell = nil;
    cell = (FormCell *)[tableView dequeueReusableCellWithIdentifier:InputCellID];
    if (cell == nil) {
        cell = [[[FormCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:InputCellID] autorelease];
    }

    cell.textLabel.text = @"Name";
    cell.inputField.placeholder = @"Name";

    return cell;
}

EDIT:

I just figured out that because I was using UIModalPresentationStylePageSheet, the max. FPS is 25. If i use UIModalPresentationStyleFormSheet, the max. FPS is 36. max FPS is 56 for UIModalPresetnationStyleFullScreen.

Can any one explain to me why the scroll performance is so bad with PageSheet? That is really what I want to use over FullScreen.

0

精彩评论

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