Use of common attribute methods for iOS development UITableView

Source: Internet
Author: User

Some properties and methods are always not clear, can only be written down, easy to find

If you have help please support, no help please tell me where to improve! Thank you!

Viewcontroller.m

Tableviewall

#import "ViewController.h"

@interface Viewcontroller () <uitableviewdelegate, uitableviewdatasource>

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

Self.view.backgroundColor = [Uicolor Yellowcolor];

[Self setuptableview];

}

-(void) Setuptableview

{

UITableView *mytblview = [[UITableView alloc]initwithframe:cgrectmake] [UIScreen mainscreen].bounds.size.width -Max, [UIScreen mainscreen].bounds.size.height-40] style:uitableviewstyleplain];

Uitableviewstyleplain,//Standard table view style

uitableviewstylegrouped//grouped table view style

Mytblview.delegate = self;

Mytblview.datasource = self;

TableView background Color

Mytblview.backgroundcolor = [Uicolor Browncolor];

Cell Split line only shows half right (set cell split line length)

Mytblview.separatorinset=uiedgeinsetsmake (0, MYTBLVIEW.FRAME.SIZE.WIDTH/2, 0,0);

The color of the cell's split line is not a property of the cell, it belongs to the Separatorcolor property of TableView.

[Mytblview Setseparatorcolor:[uicolor Redcolor];

To cancel a cell's split line

Mytblview.separatorstyle = Uitableviewcellseparatorstylenone;

Uitableviewcellseparatorstylesingleline system default

Uitableviewcellseparatorstylesinglelineetched This delimited style only supports the current grouped style sheet view (with less)

To cancel the scroll bar to the right of TableView

Mytblview.showsverticalscrollindicator = NO;

Set the offset of the TableView

[Mytblview setcontentoffset:cgpointmake (0) Animated:yes];

Dynamically hide the bottom line of TableView when TableView data is low

Mytblview.tablefooterview = [[UIView alloc]init];

Hide TableView's Footerview

mytblview.sectionfooterheight = 0;

[Self.view Addsubview:mytblview];

}

Display the search button in the TableView index

-(Nsarray *) Sectionindextitlesfortableview: (UITableView *) TableView

{

Nsmutablearray *arr = [[Nsmutablearray alloc] initwithcapacity:0];

[Arr addobject:@ "{search}"];//equivalent to [arr Addobject:uitableviewindexsearch];

return arr;

}

Cell Click Trigger Method

-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath

{

TableView selected when reversed

[TableView Deselectrowatindexpath:indexpath Animated:yes];

}

-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{

Number of cells

return 10;

}

-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath

{

Cell height

return 30;

}

Cell Default background color modification

-(void) TableView: (UITableView *) TableView Willdisplaycell: (UITableViewCell *) cell Forrowatindexpath: (Nsindexpath *) Indexpath {

Cell.backgroundcolor = [Uicolor Graycolor];

}

Set the cell

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath

{

static NSString *ident = @ "Shool";

UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:ident];

if (!cell) {

cell = [[UITableViewCell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:ident];;

}

Background color when cell is selected

Uiimageview *imageview = [[Uiimageview alloc]init];

Imageview.backgroundcolor = [Uicolor Yellowcolor];

Cell.selectedbackgroundview = ImageView;

Cell.backgroundcolor = [Uicolor Whitecolor];

/*

Cell.accessorytype =uitableviewcellaccessorynone;//cell doesn't have any style.

Cell.accessorytype =uitableviewcellaccessorydisclosureindicator;//cell has a small arrow on the right, more than 10 pixels from the right.

Cell.accessorytype =uitableviewcellaccessorydetaildisclosurebutton;//cell has a blue round button on the right;

Cell.accessorytype =uitableviewcellaccessorycheckmark;//cell to the right of the shape is a checkmark;

Cell.selectionstyle =uitableviewcellselectionstylenone;//cell The style of the selected state, for the enumeration type

*/

return cell;

}

/*

Get location information for multiple select cells

-(Nsarray *) indexpathsforselectedrows;

TableView edit (Attribute Class)

Set whether it is an edit state (a minus sign appears to the left of the cell in the edit state, click the Delete button on the right)

@property (nonatomic, getter=isediting) BOOL editing;

-(void) setediting: (BOOL) editing animated: (bool) animated;

Sets whether the cell can be selected (default = yes)

@property (nonatomic) BOOL allowsselection;

Set whether cell editing mode can be selected

@property (nonatomic) BOOL allowsselectionduringediting;

Set whether multiple selections are supported

@property (nonatomic) BOOL allowsmultipleselection;

Set whether multiple selections are supported in edit mode

@property (nonatomic) BOOL allowsmultipleselectionduringediting;

Get cell by Location path

-(UITableViewCell *) Cellforrowatindexpath: (Nsindexpath *) Indexpath;

TableView inserting partitions

-(void) Insertsections: (Nsindexset *) Sections withrowanimation: (uitableviewrowanimation) animation;

Delete Partition

-(void) Deletesections: (Nsindexset *) Sections withrowanimation: (uitableviewrowanimation) animation;

Overloading a partition

-(void) Reloadsections: (Nsindexset *) Sections withrowanimation: (uitableviewrowanimation) animation;

Move a partition

-(void) Movesection: (nsinteger) Section tosection: (Nsinteger) newsection;

Insert some rows

-(void) Insertrowsatindexpaths: (Nsarray *) indexpaths withrowanimation: (uitableviewrowanimation) animation;

Delete some rows

-(void) Deleterowsatindexpaths: (Nsarray *) indexpaths withrowanimation: (uitableviewrowanimation) animation;

Overloading some rows

-(void) Reloadrowsatindexpaths: (Nsarray *) indexpaths withrowanimation: (uitableviewrowanimation) animation;

Move a row

-(void) Moverowatindexpath: (Nsindexpath *) Indexpath Toindexpath: (Nsindexpath *) Newindexpath;

The animation parameter is an enumeration that enumerates the animation types as follows

uitableviewrowanimationfade,//fade in and fade out

uitableviewrowanimationright,//slide right into the

uitableviewrowanimationleft,//slide in from left

uitableviewrowanimationtop,//slide in from top

uitableviewrowanimationbottom,//from slipping into

Uitableviewrowanimationnone,//No animations

Uitableviewrowanimationmiddle,

uitableviewrowanimationautomatic = 100//Automatically select the appropriate animation

*/

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

Dispose of any resources the can be recreated.

}

@end

Use of common attribute methods for iOS development UITableView

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.