ios--Click Sectionheader to jump, different sectionheader tags are different

Source: Internet
Author: User

Recently asked the first few sectionheader to jump interface, different sectionheader have the same title, as shown in the figure:

Shanghai Expo that piece is Sectionheader click to jump, and there are two sections each section content is different, the code is as follows:

Inside added gestures: uitapgesturerecognizer, a lot of blog wrote a single finger or multi-finger gestures, here is not speaking, because sister I also did not learn, basically is to ask what to do, learn what.

If you just want to add a different section in the beginning, I have written in another blog, and I do not want to always reprint others, on-line check is the same code or not the same person, is the heart tired of AH small partners!

Okay, nonsense dollars, the code is as follows:

1. First make sure you have TableView, and will set up cell, section, not the words to learn ~

-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView

{

return 2; Number of sections 2

}

2. The main code, the other does not need, of course, if you really will set up a cell, as long as the file in your resume to enter this paragraph can be, the specific way to jump to explain the

-(UIView *) TableView: (UITableView *) TableView viewforheaderinsection: (nsinteger) Section

{

UIView *view = [[UIView alloc] init];//I set up a view in Sectionheader

if (section ==0) {//which section is judged

UITapGestureRecognizer *TAPG = [[UITapGestureRecognizer alloc]init];

[TAPG addtarget:self Action: @selector (Sj_tap:)]; Jump action, Sister is to use Sj_tap: Define my jump function

tapg.numberoftapsrequired=1; A finger jump, you know Apple can create multi-finger gestures

[View Setuserinteractionenabled:yes];

UILabel *label =[[uilabel alloc] Initwithframe:cgrectmake (0, 0, 320, 30)]; CGRect must be set up otherwise the interface was created at the beginning and can't be found, sister.

[Label settext:@ "Shanghai World Expo Co., Ltd."]; Add my Word, this label is the same as the usual label setting method

[View ADDGESTURERECOGNIZER:TAPG];

[View Addsubview:label];

}

if (section = = 1) {//This and the previous, I did not write full

UITapGestureRecognizer *TAPG1 = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (Sj_tap:)];

UILabel *label1 =[[uilabel alloc] Initwithframe:cgrectmake (0, 0, 220, 30)];

[Label1 settext:@ "Shanghai World Expo Supply Chain Co., Ltd."];

[View ADDGESTURERECOGNIZER:TAPG1];

[View Addsubview:label1];

}

return view;

}

My jump code, this I think should be written out, because the details may make you tune for a long time, sister is only her own experience

-(void) Sj_tap: (uigesturerecognizer*) sender//attention differs from usual

{

Teweditexposubsidiarysupervisorviewcontroller *te = [[Teweditexposubsidiarysupervisorviewcontroller alloc]init]; Sister cares about the name of the screen to jump to

[Self presentviewcontroller:te animated:yes completion:nil];

}

Just add these two pieces of code in it, no extra settings,. h file is what you originally, want is directly can use code. Hope to be useful for beginners.

my giuhub Address: https://github.com/leroypus/WGJDemo.git, above will pass some I do the pure code to do the interface demo and I do some of the project demo, welcome follow, welcome to star. This project will also be uploaded after completion, the need for friends can be downloaded in a period of time.

ios--Click Sectionheader to jump, different sectionheader tags are different

Related Article

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.