[ad_1]
the variety of cell is 30, scroll to fifteen after 5 second in viewDidLoad
UITableView will create redundant reuse cell after scrolling to invisible cell.
code:
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any extra setup after loading the view.
[self.view addSubview:self.tableView];
self.tableView.body = self.view.body;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
self.tableView.separatorColor = UIColor.whiteColor;
self.tableView.estimatedRowHeight = 52;
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass(UITableViewCell.class)];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:15 inSection:0] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
});
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)part
{
return 30;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(UITableViewCell.class)];
cell.backgroundColor = [self.class randomColorWithAlpha:1];
return cell;
}
[ad_2]
