Is a UITableView slow, even with multiple objects?

- (void)viewDidLoad { [super viewDidLoad]; [self.tableView setRowHeight:100]; [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; [self.view setBackgroundColor:[UIColor groupTableViewBackgroundColor]]; } #pragma mark - #pragma mark Table view data source // Customize the number of sections in the table view. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 3; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, 100) reuseIdentifier:CellIdentifier] autorelease]; // For Name/Phone: UITextField *name = [[[UITextField alloc] initWithFrame:CGRectMake(75, 22, 200, 25)] autorelease]; [name setFont:[UIFont systemFontOfSize:14]]; [name setPlaceholder:@"John Doe"]; [name setReturnKeyType:UIReturnKeyDone]; [name setAutocapitalizationType:UITextAutocapitalizationTypeWords]; [name setAutocorrectionType:UITextAutocorrectionTypeNo]; [name setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter]; UITextField *phone = [[[UITextField alloc] initWithFrame:CGRectMake(75, 67, 200, 25)] autorelease]; [phone setFont:[UIFont systemFontOfSize:14]]; [phone setPlaceholder:@"0412 123 123"]; [phone setReturnKeyType:UIReturnKeyDone]; //[phone setKeyboardType:UIKeyboardTypePhonePad]; [phone setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter]; UIImageView *background = [[[UIImageView alloc] initWithFrame:CGRectMake(9, 11, 302, 89)] autorelease]; background.image = [UIImage imageNamed:@"book-personaldetailsbg.png"]; // Add to the View [cell addSubview:background]; [cell addSubview:name]; [cell addSubview:phone]; // Add actions: [name addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit]; [phone addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit]; } return cell; } 

Is there a reason for this? I have only a few objects, so I canโ€™t understand why this will be behind. It jumps, not my phone, because the settings app is working fine.

+1
source share
4 answers

UITableViewCells with many subqueries is slowly displayed on the iPhone due to the way the phone displays each layer.

Read this: http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/

The information provided in the above message is still extremely relevant and useful, but the example of loading the project does not work (as of December 8, 2011). However, Apple, having documentation on the desktop view, had examples of flat table cells for quick scrolling for a log while now. Check this out: http://developer.apple.com/library/ios/#samplecode/AdvancedTableViewCells/Introduction/Intro.html

Highlights:

  • iPhone doesn't handle Alpha very fast.
  • Subviews must have the opaque property set to YES
  • If possible, draw your objects in one opaque view for better performance.

Obviously, the cells with the controls you need to manipulate cannot be flattened, so I think you just need to try to get away, making sure that the hidden objects of your camera are opaque.

The last thing I would suggest is not to allocate new objects every time a cell is requested - this is certainly a bottleneck in your code. You must use reusable cells and subclass the cell so that its fields are highlighted and added as sub-items only when they are first created. Subsequent calls should deactivate the cell and use prepareForReuse to clear the old values.

+10
source

I thought you should not set the cell height, just like you. I believe that you should implement the method heightForCellAtIndexPath (it may not have this name 100% on the right), and it asks your delegate how tall it should make each individual cell. I feel like I've heard about performance issues if I havenโ€™t done the โ€œrightโ€ way. IMHO

The first thing I will try if I were you is to comment on all the code associated with the image and see if the table speeds up.

0
source

Start by removing the background of the cell. See if that matters.

0
source

Here are the solution guys, inside the block add images to upload and what it is:

  dispatch_queue_t queue = dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
     dispatch_async (queue, ^ {
         NSData * data = [NSData dataWithContentsOfURL: [NSURL URLWithString:
                                                       [[feeds objectAtIndex: indexPath.row]
                                                        objectForKey: @ "url"]]];
         UIImage * image = [UIImage imageWithData: data];
         dispatch_async (dispatch_get_main_queue (), ^ {
             cell.imagen.image = image;
         }); 

Use Grand Central Dispatch for priority. I can explain if someone wants to, just write me on info@tonymedrano.com

0
source

Source: https://habr.com/ru/post/894055/


All Articles