IOS Click on the TableView cell to roll it to the top of the screen

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.