iOS development TableView, multiple Tableviewcell, custom cell, cell painting (Storyboard + code mode)

Source: Internet
Author: User

Recently to do a project, there is an account settings interface, read Weibo, QQ, their account settings are compared to the original ecosystem did not do anything to deal with. Rain doctor's account is good, do a lot of processing. Don't talk nonsense directly on the code.

The first step:

//usertableviewcell.h This defines the first type of cell #import <UIKit/UIKit.h>@interface**userviewcellname; @end
//usertableviewcell2.h the second type of cell is defined here, #import <UIKit/UIKit.h>@interface**userviewcell2image; @end

The TableView in the storyboard and the cell's class and cell identifier don't say a word.

Cases:

2, after the design of these things, began to enter the Tableviewcontroller:

//user TableViewController.h #import <UIKit/UIKit.h>@interface**listgroupname; @end
//USERTABLEVIEWCONTROLLER.M#import "UserTableViewController.h"#import "UserTableViewCell.h"#import "UserTableViewCell2.h"@interfaceUsertableviewcontroller ()@end@implementationUsertableviewcontroller- (void) viewdidload{[Super Viewdidload];Self.tableView.separatorStyle = Uitableviewcellaccessorynone;//Remove Split LineNSBundle*bundle =[NSBundle Mainbundle]; NSString*plistpath = [Bundle Pathforresource:@"Userviewcell"OfType:@"plist"];Self. Userviewcelldic =[[Nsdictionary Alloc]initwithcontentsoffile:plistpath]; Self.listgroupname=[Self.  Userviewcelldic AllKeys]; Self.listgroupname =[Self.listgroupname sortedarrayusingselector: @selector (compare:)];//Sort}-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview//Returns a few section{return[Self.listgroupname Count];}-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) section//section header name is set to null {NSString *groupname =@" "; returnGroupName;}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section//number of rows per section {NSString*groupname =[Self.listgroupname objectatindex:section]; Nsarray*listitem =[Self.    Userviewcelldic Objectforkey:groupname]; return[ListItem Count]; }#pragmamark-tableviewdatasource-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{StaticNSString *userviewcellidentifier =@"Usertableviewcell"; StaticNSString *userviewcellidentifier2 =@"UserTableViewCell2"; Nsuinteger Section=[Indexpath section]; Nsuinteger Row=[Indexpath Row]; NSString*groupname =[Self.listgroupname objectatindex:section]; Nsarray*listitem =[Self.    Userviewcelldic Objectforkey:groupname]; Nsdictionary*rowdict =[ListItem Objectatindex:row]; if(0==Section ) {UserTableViewCell2*cell =[TableView Dequeuereusablecellwithidentifier:userviewcellidentifier2]; Cell.name.text= [Rowdict Objectforkey:@"name"]; NSString*imagepath = [Rowdict objectforkey:@"Image"]; ImagePath= [ImagePath stringbyappendingstring:@". PNG"]; Cell.userviewcell2image.image=[UIImage Imagenamed:imagepath]; Cell.accessorytype= Uitableviewcellaccessorydisclosureindicator;//the last arrow//Draw LineUIView *view = [[UIView alloc]initwithframe:cgrectmake (0, -, the,1)]; UIView*leftview = [[UIView alloc]initwithframe:cgrectmake (0,0,3, the)]; UIView*rightview = [[UIView alloc]initwithframe:cgrectmake (317,0,3, the)]; View.backgroundcolor= [Uicolor colorwithred: +/255.0fGreen +/255.0fBlue233/255.0fAlpha1]; Leftview.backgroundcolor= [Uicolor colorwithred: +/255.0fGreen +/255.0fBlue233/255.0fAlpha1]; Rightview.backgroundcolor= [Uicolor colorwithred: +/255.0fGreen +/255.0fBlue233/255.0fAlpha1];        [Cell.contentview Addsubview:view];        [Cell.contentview Addsubview:leftview];        [Cell.contentview Addsubview:rightview]; returncell; }Else{Usertableviewcell*cell =[TableView Dequeuereusablecellwithidentifier:userviewcellidentifier]; Cell.userviewcellname.text= [Rowdict Objectforkey:@"name"]; NSString*imagepath = [Rowdict objectforkey:@"Image"]; ImagePath= [ImagePath stringbyappendingstring:@". PNG"]; Cell.userviewcellicon.image=[UIImage Imagenamed:imagepath]; Cell.accessorytype= Uitableviewcellaccessorydisclosureindicator;//the last arrow//Draw LineUIView *view = [[UIView alloc]initwithframe:cgrectmake (0, the, the,1)]; UIView*leftview = [[UIView alloc]initwithframe:cgrectmake (0,0,3, +)]; UIView*rightview = [[UIView alloc]initwithframe:cgrectmake (317,0,3, +)]; View.backgroundcolor= [Uicolor colorwithred: +/255.0fGreen +/255.0fBlue233/255.0fAlpha1]; //Alpha is transparencyLeftview.backgroundcolor = [Uicolor colorwithred: +/255.0fGreen +/255.0fBlue233/255.0fAlpha0.3]; Rightview.backgroundcolor= [Uicolor colorwithred: +/255.0fGreen +/255.0fBlue233/255.0fAlpha1];        [Cell.contentview Addsubview:view];        [Cell.contentview Addsubview:leftview];         [Cell.contentview Addsubview:rightview]; returncell; }          }-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Height of Indexpath//cell {nsuinteger section=[Indexpath section]; if(0==Section ) {        return  the; }Else{        return  +; }   }

The plist file is attached here:

3. Operation Effect:

Writing is not particularly detailed, if there is any do not understand or need to leave the source of the mailbox!

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.