简体   繁体   English

我需要做哪些优化才能为uitableview性能ipad做更多

[英]what optimisation i need to do more for uitableview performance ipad

i have gone through different threads on stack overflow, and adopted them in my implementation of table view. 我在堆栈溢出中经历了不同的线程,并在我的表视图实现中采用了它们。 some of them are: 他们之中有一些是:

tblOrderView.delaysContentTouches = NO;//order performance
tblOrderView.canCancelContentTouches = NO;//order performance
tblOrderView.showsHorizontalScrollIndicator = NO;//order performance

i am using different reload variants like reload rows at indexes and insert row at index paths, where ever possible instead of reload data. 我正在使用不同的重载变体,例如在索引处重载行并在索引路径处插入行,只要可能就代替重载数据。

i am reusing cell in proper way by c==nil check, creating content views in cell == nil and accessing content view by view with tag. 我正在通过c == nil检查以适当的方式重用单元格,在cell == nil中创建内容视图,并通过带有标签的视图访问内容视图。

i am not fetching UIImage image name again and again, i keep a reference in instance variable. 我没有一次又一次地获取UIImage图像名称,我在实例变量中保留了一个引用。

My table view, cell and content have to be transparent as per design provided by client. 根据客户提供的设计,我的表格视图,单元格和内容必须透明。

i am not sure about my heightForRowAtIndexPath implementation please have a look below cell for row.... implementation, it is working as expected. 我不确定我的heightForRowAtIndexPath实现,请在单元格下面查看行...实现,它按预期工作。 Problem: when i continue inserting row at index path after 30 to 35 insertions my table performance degrades (i am calling insert row not reload data for high performance). 问题:当我在30到35次插入后继续在索引路径中插入行时,我的表性能下降(我在调用插入行而不是为了高性能而重新加载数据)。 my cell for row relevant code is : 我的行相关代码的单元格是:

NSString *cellIdentifier=[NSString stringWithFormat:@"Modifiers%d",numberOfModifiers];;

customCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
[customCell setSelected:NO animated:NO];
if(customCell==nil){
    [customCell setBackgroundColor:[UIColor clearColor]];
    customCell=[self reusableTableViewCellContent:cellIdentifier ForModifier:numberOfModifiers indexPath:indexPath];
}

reusableTableViewCellContent:cellIdentifier implementation is : reusableTableViewCellContent:cellIdentifier实现是:

-(UITableViewCell *)reusableTableViewCellContent:(NSString *)identifier ForModifier:(int)_modifier indexPath:(NSIndexPath *)indexPath{

UITableViewCell *cell=nil;


//NSLog(@"%@",identifier);
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
cell.selectionStyle=UITableViewCellSelectionStyleNone;


CustomButton *btnDecimalQty=[[CustomButton alloc]initWithFrame:CGRectMake(5, 10, 57, 24)];

[btnDecimalQty setBackgroundImage:imgQuantity forState:UIControlStateNormal];
[btnDecimalQty setTag:DECIMAL_QUANTITY_BUTTON];
btnDecimalQty.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:15.0];
[btnDecimalQty setTitleColor:[UIColor colorWithRed:71.0/255.0 green:72.0/255.0 blue:72.0/255.0 alpha:1.0] forState:UIControlStateNormal];
[btnDecimalQty addTarget:self action:@selector(openKeyPadPopUp:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:btnDecimalQty];

float prod_origin_x = btnDecimalQty.frame.origin.x + btnDecimalQty.frame.size.width + 5;



UILabel *productName=[[UILabel alloc]initWithFrame:CGRectMake(prod_origin_x , 8, 178, 30)]; //163, 140, 220, 30
//  [productName setText:@"Potato Wedges"];
[productName setFont:[UIFont fontWithName:@"Arial-BoldMT" size:[[Utils getFontSize] floatValue]]];
[productName setBackgroundColor:[UIColor clearColor]];
[productName setTextAlignment:UITextAlignmentLeft];
[productName setTextColor:[UIColor colorWithRed:45.0/255.0 green:44.0/255.0 blue:44.0/255.0 alpha:1.0]];
[productName setTag:PRODUCT_NAME_LABEL];
[cell.contentView addSubview:productName];


float action_button_origin_x = productName.frame.origin.x + productName.frame.size.width + 2;



CustomButton *edit=[[CustomButton alloc]initWithFrame:CGRectMake(action_button_origin_x, 14, 31, 23)];
[edit setTag:EDIT_BUTTON];


[edit setBackgroundImage:imgEdit forState:UIControlStateNormal];
[edit addTarget:self action:@selector(edit:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:edit];



CustomButton *discount=[[CustomButton alloc]initWithFrame:CGRectMake(edit.frame.origin.x+0 + edit.frame.size.width + 2, 14, 31, 23)];
[discount setTag:DISCOUNT_BUTTON];

[discount setBackgroundImage:imgDiscount forState:UIControlStateNormal];
[discount addTarget:self action:@selector(discount:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:discount];

float prod_amount_orgin_x = discount.frame.origin.x + discount.frame.size.width + 1;


UILabel *amount=[[UILabel alloc]initWithFrame:CGRectMake(prod_amount_orgin_x , 8, 65, 30)];
//  [amount setText:@"$ 70.00"];
[amount setBackgroundColor:[UIColor clearColor]];
[amount setTextAlignment:UITextAlignmentRight];
[amount setAdjustsFontSizeToFitWidth:YES];
[amount setFont:[UIFont fontWithName:@"Arial-BoldMT" size:[[Utils getFontSize] floatValue]]];
[amount setTextColor:[UIColor colorWithRed:71.0/255.0 green:72.0/255.0 blue:72.0/255.0 alpha:1.0]];
[amount setTag:AMOUNT_LABEL];
[cell.contentView addSubview:amount];


for(int i=0;i<_modifier ;i++)
{
    UILabel *modifierName=[[UILabel alloc]initWithFrame:CGRectMake(prod_origin_x, 30+(i*30), 220, 30)];
    //      [modifierName setText:@"Modifier 1"];
    [modifierName setFont:[UIFont fontWithName:@"Arial-BoldMT" size:[[Utils getFontSize] floatValue]]];
    [modifierName setBackgroundColor:[UIColor clearColor]];
    [modifierName setTextAlignment:UITextAlignmentLeft];
    [modifierName setTextColor:[UIColor colorWithRed:45.0/255.0 green:44.0/255.0 blue:44.0/255.0 alpha:1.0]];
    [modifierName setTag:MODIFIER_NAME_LABEL+(i*2)];
    [cell.contentView addSubview:modifierName];


    UILabel *modifierAmount=[[UILabel alloc]initWithFrame:CGRectMake(prod_amount_orgin_x, 30+(i*30), 65, 30)];
    //      [modifierAmount setText:@"$0.50"];
    [modifierAmount setBackgroundColor:[UIColor clearColor]];
    [modifierAmount setTextAlignment:UITextAlignmentRight];
    [modifierAmount setFont:[UIFont fontWithName:@"Arial-BoldMT" size:[[Utils getFontSize] floatValue]]];
    [modifierAmount setTextColor:[UIColor colorWithRed:71.0/255.0 green:72.0/255.0 blue:72.0/255.0 alpha:1.0]];
    [modifierAmount setTag:MODIFIER_AMOUNT_LABEL+(i*2)];
    [modifierAmount setAdjustsFontSizeToFitWidth:YES];
    [cell.contentView addSubview:modifierAmount];

}


    return cell;

} }

my heightForRow implementation.... 我的heightForRow实现...

 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Product *product=(Product *)[self.arrOrderDetail objectAtIndex:indexPath.row];

    //Modifiers
    NSArray *modifierList=product.mModifiersAdded;
    int numberOfModifiers=0;
    for(Modifier *modifier in modifierList)
    {
        for(ModifierItem *modifierItem in modifier.activeModifiers)
        {
            numberOfModifiers++;
        }
    }

    OrderModule *module=[OrderModule sharedModule];
    numberOfModifiers=numberOfModifiers+[[module getActiveCustomModifiers:product.mOrderDetailId] count];


    //Non time based discount
    if([product.mNonTimeBasedDiscounts floatValue]>0.0)
    {
        numberOfModifiers++;
    }
    else if([product.mRuntimeDiscount floatValue]>0.0)       //Run time based discount
    {
        numberOfModifiers++;
    }
    else if([product.mTimeBasedDiscounts floatValue]>0.0)
    {
        numberOfModifiers++;
    }


    //Amount Modifier
    if(numberOfModifiers>0)
    {
        numberOfModifiers++;
    }

    CGFloat extraHeight=0.0;
    if(numberOfModifiers==0)
        extraHeight=15.0;
    return 30.0+extraHeight+(numberOfModifiers*30.0);
}

please suggest what more optimisations i can make to increase uitableview performance (reloading and scrolling) 请提出我可以做些什么优化来提高uitableview的性能(重新加载和滚动)

Thanks. 谢谢。

I presume that you are setting the UILabel tags so that you can search for the fields when you providing the content? 我假设您正在设置UILabel标记,以便在提供内容时可以搜索字段? Why don't you create a custom UITableViewCell subclass that stores the labels in two NSMutableArrays? 为什么不创建一个自定义UITableViewCell子类来将标签存储在两个NSMutableArrays中? Then you can just select the appropriate label from the array rather than having to incur a linear search through the view hierarchy for every label in every cell? 然后,您可以从数组中选择适当的标签,而不必在视图层次结构中对每个单元格中的每个标签进行线性搜索?

When setting up your cell you call several methods inside the loops that could be called outside so you could have 设置单元格时,您可以在循环内部调用多个方法,而这些方法可以在外部调用,这样您就可以

UIFont *arialFont=[UIFont fontWithName:@"Arial-BoldMT" size:[[Utils getFontSize] floatValue]];
UIColor *amountColor=[UIColor colorWithRed:71.0/255.0 green:72.0/255.0 blue:72.0/255.0 alpha:1.0];
UIColor *nameColor=[UIColor colorWithRed:45.0/255.0 green:44.0/255.0 blue:44.0/255.0 alpha:1.0];

UILabel *amount=[[UILabel alloc]initWithFrame:CGRectMake(prod_amount_orgin_x , 8, 65, 30)];
//  [amount setText:@"$ 70.00"];
[amount setBackgroundColor:[UIColor clearColor]];
[amount setTextAlignment:UITextAlignmentRight];
[amount setAdjustsFontSizeToFitWidth:YES];
[amount setFont:arialFont];
[amount setTextColor:amountColor];
[amount setTag:AMOUNT_LABEL];
[cell.contentView addSubview:amount];


for(int i=0;i<_modifier ;i++)
{
    UILabel *modifierName=[[UILabel alloc]initWithFrame:CGRectMake(prod_origin_x, 30+(i*30), 220, 30)];
    //      [modifierName setText:@"Modifier 1"];
    [modifierName setFont: setFont:arialFont];
    [modifierName setBackgroundColor:[UIColor clearColor]];
    [modifierName setTextAlignment:UITextAlignmentLeft];
    [modifierName setTextColor: nameColor];
    [modifierName setTag:MODIFIER_NAME_LABEL+(i*2)];
    [cell.contentView addSubview:modifierName];


    UILabel *modifierAmount=[[UILabel alloc]initWithFrame:CGRectMake(prod_amount_orgin_x, 30+(i*30), 65, 30)];
    //      [modifierAmount setText:@"$0.50"];
    [modifierAmount setBackgroundColor:[UIColor clearColor]];
    [modifierAmount setTextAlignment:UITextAlignmentRight];
    [modifierAmount setFont: setFont:arialFont];
    [modifierAmount setTextColor:amountColor];
    [modifierAmount setTag:MODIFIER_AMOUNT_LABEL+(i*2)];
    [modifierAmount setAdjustsFontSizeToFitWidth:YES];
    [cell.contentView addSubview:modifierAmount];

}

Also, in this code - 另外,在此代码中-

for(Modifier *modifier in modifierList)
{
    for(ModifierItem *modifierItem in modifier.activeModifiers)
    {
        numberOfModifiers++;
    }
}

What type is modifier.activeModifiers ? 是什么类型modifier.activeModifiers If it is an NSArray or NSDictionary then the inner loop can simply be replaced with numberOfModifiers+=[modifier.activeModifiers count]; 如果它是NSArrayNSDictionary则可以将内部循环简单地替换为numberOfModifiers+=[modifier.activeModifiers count];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 需要优化以计算和加载uitableview - Need optimisation for calculating and loading uitableview 对于 UITableView,我需要实现 trailingSwipeActionsConfigurationForRowAt 和/或 editActionsForRowAt 吗? - For UITableView do I need to implement trailingSwipeActionsConfigurationForRowAt and/or editActionsForRowAt? 如何提高UITableView的滚动性能? 我想念我什么? - How to improve UITableView scrolling performance? What I am I missing? 除了使用启动情节提要板以外,我还需要做什么来支持iPad Pro的全分辨率? - Other than using a launch storyboard, what else do I need to do to support the iPad Pro's full resolution? 我发布了所有我可以发布的 memory,但是我的程序需要更多,我该怎么办? - I release all memory that I can, but my program need more, what can I do? 我需要使用Adobe AIR为iPad开发什么? - What I Need To Use Adobe AIR To Develop For iPad? 将AIR应用程序移植到iOS:我需要iPad来调试该应用程序吗? - Porting AIR app to iOS: do I need an iPad to debug the app? 我是否需要在iPod touch,iPad和iPhone上单独测试? - Do I need to separately test on iPod touch, iPad and iPhone? 我需要Mac OS X 10.6才能为iPad开发吗? - Do I need Mac OS X 10.6 to develop for the iPad? 我是否需要iPhone和iPad故事板的多个视图控制器? - Do I need multiple view controllers for the iPhone & iPad storyboards?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM