Click on the TableView cell to roll it to the top of the screen, and many e-commerce classification modules Use this approach 1. Sample code
-(void) Viewdidload {
[Super Viewdidload];
[Self addtableview];
}
#pragma mark-Create TableView
-(void) Addtableview
{
UITableView *tableview = [[UITableView alloc]init];
Tableview.frame = Self.view.bounds;
Tableview.delegate = self;
Tableview.datasource = self;
[Self.view Addsubview:tableview];
}
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath
{
1. Create a cell
static NSString *id = @ "Cell";
UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:id];
if (cell = = nil) {
cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:id];
}
2. Setting the cell's data
Cell.textLabel.text = [NSString stringwithformat:@ "%ld", (long) indexpath.row];
return cell;
}
#pragma mark-click cell call
-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath
{
[TableView scrolltorowatindexpath:indexpath atscrollposition:uitableviewscrollpositiontop Animated:YES]; //Key code
}
2. Parameter Description:
Uitableviewscrollpositionnone, no matter, the top, the bottom can be, as long as the fastest appearance in the screen range
Uitableviewscrollpositiontop, click on the line that is pinned
Uitableviewscrollpositionmiddle, click on the line to place the middle
Uitableviewscrollpositionbottom Click on the bottom of the row
IOS Click on the TableView cell to roll it to the top of the screen