Basic usage of iOS TableView

Source: Internet
Author: User

</pre><p> @implementation viewcontroller-(void) viewdidload {<span style= "font-size:12px" >    [Super viewdidload];        UITableView *tableview = [[UITableView alloc] initWithFrame: CGRectMake (0, 0, self.view.frame.size.width, self.view.frame.size.height-64) style:uitableviewstyleplain];// Note: TableStyle also has a grouped type, with this will appear on the tableview above the blank </span></p><p><span style= "font-size:12px ">    tableview.delegate = self;    Tableview.datasource = self;   //Set header//  &NBSP ; UIView *view = [[UIView alloc] Initwithframe:cgrectmake (0, 0, self.view.frame.size.width,)];//    View.backgroundcolor = [Uicolor redcolor];   //Take a picture as header     Uiimageview *imagev = [[Uiimageview allo C] Initwithframe:cgrectmake (0, 0, self.view.frame.size.width, max)];    imagev.image = [UIImage imagenamed:@] Tu.jpg "];    Tableview.tableheaderview = imagev;    [Self.view addsubview:tableview];        </span>   //zoning    & Nbsp;</p><p class= "P1" style= "margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:arial; font-size:14px; line-height:26px "><span class=" S1 "> [</span><span class=" S2 ">tableview   < /span>setseparatorcolor<span class= "S1" >:[</span>uicolor    <span class= "S1" ></ Span>bluecolor<span class= "S1" >]];  //set the split line to Blue </span></p><p class= "P1" style= "margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:arial; font-size:14px; line-height:26px "><span class=" S1 "></span></p><p class=" P1 "style=" margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:arial; font-size:14px; Line-height:26px "> Hide UITableViewCell Divider line </p><p class=" P1 "style=" margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:arial; font-size:14px; Line-height:26px ">[self.mytableview       Setseparatorstyle:uitableviewcellseparatorstylenone];  </p><p class= "P2" style= "margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:arial; font-size:14px; line-height:26px "></p><p class=" P1 "style=" margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:arial; font-size:14px; Line-height:26px "> uitableviewcellseparatorstyle has the following several  </p><p class=" P1 "style=" margin-top : 0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:arial; font-size:14px; line-height:26px "><span class=" S1 ">typedef</span> <span class=" S2 ">NS_ENUM</span > (Nsinteger, Uitableviewcellseparatorstyle) {</p><p class= "P1" style= "margin-top:0px; margin-bottom:0px ; padding-top:0px; padding-bottom:0px; font-family:arial; Font-size:14px; Line-height:26px ">    uitableviewcellseparatorstylenone,</p><p class=" P1 "style=" margin-top : 0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:arial; font-size:14px; Line-height:26px ">    uitableviewcellseparatorstylesingleline,</p><p class=" P2 "style=" margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:arial; font-size:14px; line-height:26px "><span class=" S3 ">    uitableviewcellseparatorstylesinglelineetched  < /span>//This separator style was only supported for grouped style table views currently</p><p class= "P1" style = "margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:arial; font-size:14px; line-height:26px ">};</p>}<p class=" P1 "style=" margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:arial; font-size:14px; Line-height:26px "></p>-(UITableViewCell *) tAbleview: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{    Static NSString * Indentifier = @ "Cell1";    UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:indentifier] ;    if (cell = = nil) {        cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcell Stylesubtitle reuseidentifier:indentifier];   }    cell.textLabel.text = @ "Partition and header";    return cell;} -(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{   // Section represents partition   First partition two rows, other partitions 3 lines     if (sections = = 0) {        return 2;   }else I  F (section== 1) {        return 3;   }else{        return 1;    }//   return 5;//each partition is 5 rows}//partition number-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{    return 3;} Partition height-(cgfloat) TableView: (UitablevieW *) TableView heightforheaderinsection: (nsinteger) section{    return 60;} Cell Height-(cgfloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{    return 60;} Title of the partition-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) section{    if ( Section = = 0) {        return @ "A";   } else if (sections = = 1) {        R Eturn @ "B";   }else{        return @ "C";   }    }//Custom Partitioning style-(UIV Iew *) TableView: (UITableView *) TableView viewforheaderinsection: (nsinteger) section{    UIView *view = [[ UIView Alloc] Initwithframe:cgrectmake (0, 0, self.view.frame.size.width,)];    View.backgroundcolor = [ Uicolor greencolor];    return view;} -(void) didreceivememorywarning {    [Super didreceivememorywarning];   //Dispose of any resources t Hat can be recreated.} <p>@End</p><p></p><pre name= "code" class= "OBJC" > a section refresh Nsindexset *indexset=[[nsindexset Alloc]initwithindex:2]; [TableView reloadsections:indexset withrowanimation:uitableviewrowanimationautomatic];//a cell refreshes Nsindexpath * Indexpath=[nsindexpath Indexpathforrow:3 insection:0]; [TableView Reloadrowsatindexpaths:[nsarray Arraywithobjects:indexpath,nil] Withrowanimation:  Uitableviewrowanimationnone]; Http://www.cnblogs.com/wendingding/p/3801454.html found it easiest to let tableview scroll to the top of this sentence [MYTB setcontentoffset:cgpointmake (0,0) Animated:no];

//


Basic usage of iOS TableView

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.