Cooked with TableView

Source: Internet
Author: User

    1. Self.title = @ "Group table View";
    2. UITableView *tableview = [[UITableView alloc] Initwithframe:cgrectmake (0, 0, +, 568) Style:uitableviewstyleplain];
    3. Setting up the TableView data source proxy
    4. Tableview.datasource = self;
    5. Set up a proxy for TableView
    6. Tableview.delegate = self;
    7. [Self.view Addsubview:tableview];
    8. Set the head and tail views of the TableView: this sets the height of the head view, the coordinates in the X y direction are not changed, and the width cannot be modified, as is the width of the tableview.
    9. UIView *headerview = [[UIView alloc] Initwithframe:cgrectmake (0, 0, 320, 100)];
    10. Tableview.tableheaderview = Headerview;
    11. UIView *fooderview = [[UIView alloc] Initwithframe:cgrectmake (0, 0, 320, 40)];
    12. Tableview.tablefooterview = Fooderview;

16.//Setting the height of the head and tail views of a group

    1. Tableview.sectionheaderheight = 50;
    2. Tableview.sectionfooterheight = 40;

19.//Setting the height of each cell

    1. Tableview.rowheight = 50;

21.//the height of each group of head views

22.-(CGFloat) TableView: (uitableview*) TableView heightforheaderinsection: (nsinteger) Section;

23.//height of each set of tails

24.-(CGFloat) TableView: (uitableview*) TableView heightforfooterinsection: (nsinteger) Section;

25.//set TableView height of each row of cells

26.-(CGFloat) TableView: (uitableview*) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath;

29.//set the color of a split line

    1. Tableview.separatorcolor = [Uicolor Redcolor];

31.//set the style of the split line, default is Uitableviewcellseparatorstylesingleline

    1. Tableview.separatorstyle = Uitableviewcellseparatorstylesingleline;

33.//Setting the background view and background color

    1. Tableview.backgroundcolor = [Uicolor Graycolor];
    2. Tableview.backgroundview = [[Uiimageview alloc] initwithimage:[uiimage imagenamed:@ "bj.jpg"];

#pragma the protocol method of the Mark-uitableview.

38.//sets the number of TableView groups if not written by default creates a set of

39.-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView;

40.//set the number of cells for each group

41.-(Nsinteger) TableView: (uitableview*) TableView numberofrowsinsection: (nsinteger) Section;

42.//Create cell UITableViewCell, which is the view of each row displayed by Tablview

43.-(uitableviewcell*) TableView: (uitableview*) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath;

45.uitableviewcell*cell=[[uitableviewcell alloc] Initwithstyle:uitableviewcellstyledefault ReuseIdentifier:nil];

47.//to set headers for each group of header views

48.-(nsstring*) TableView: (uitableview*) TableView titleforheaderinsection: (nsinteger) Section;

49.//set the title of each group of trailer views

50.-(nsstring*) TableView: (uitableview*) TableView titleforfooterinsection: (nsinteger) Section;

51.//the head view of a custom group

52.-(uiview*) TableView: (uitableview*) TableView viewforheaderinsection: (nsinteger) Section;

53.//the tail view of a custom group

54.-(uiview*) TableView: (uitableview*) TableView viewforfooterinsection: (nsinteger) Section;

55.//setting the style when selecting

56.cell.selectionstyle = Uitableviewcellselectionstylegray;

57.//setting the background view after selection

Cell.selectedbackgroundview = view;

59.//Setting the secondary icon style

Cell.accessorytype = Uitableviewcellaccessorydetailbutton;

61.//Add a custom view to the Contentaview and do not add it directly to the cell

    1. [Cell.contentview Addsubview:titlelabel];

64.//Create a location

Nsindexpath *indexpath = [Nsindexpath indexpathforitem:1 Insection:2].

Gets the cell UITableViewCell *cell = [_tableview Cellforrowatindexpath:indexpath] at the specified location;

66.//all cell visiblecells currently displayed on the screen

67.NSArray *cellarray = [_tableview visiblecells];

68.//get all Indexpath currently displayed in the cell of the screen indexpathsforvisiblerows

69.NSArray *indexpatharray = [_tableview indexpathsforvisiblerows];

71.//scrolling to the cell at the specified location

72.//[_tableview Scrolltorowatindexpath:indexpath Atscrollposition:uitableviewscrollpositionbottom Animated:YES];

73.//refreshes the TableView, that is, to recall all implemented protocol methods

    1. [_tableview Reloaddata];

75.//refreshes the cell of the specified Indexpath

76.[_tableview Reloadrowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationautomatic];

77.//Refresh the specified section (group)

    1. Nsindexset *indexset = [Nsindexset indexsetwithindex:0];
    2. [_tableview Reloadsections:indexset Withrowanimation:uitableviewrowanimationfade];

81.//Adding an indexed view

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

83.{

    1. return @[@ "A", @ "B", @ "C", @ "D", @ "E", @ "F", @ "G", @ "H"];

85.}

86.//setting the color of indexed view text

    1. Tableview.sectionindexcolor = [Uicolor Whitecolor];

88.//background color of indexed views

    1. Tableview.sectionindexbackgroundcolor = [Uicolor Graycolor];

90.//the method that is called after clicking on the indexed view, including the title and location of the click Index position

91.-(Nsinteger) TableView: (uitableview*) TableView sectionforsectionindextitle: (NSString *) title Atindex: (Nsinteger ) index;

92.//cell will be displayed on the screen when the call

93.-(void) CollectionView: (uicollectionview*) CollectionView Willdisplaycell: (uicollectionviewcell*) cell Foritematindexpath: (Nsindexpath *) Indexpath;

94.//cell end is displayed on the screen when the call

95.-(void) CollectionView: (uicollectionview*) CollectionView Didenddisplayingcell: (uicollectionviewcell*) cell Foritematindexpath: (Nsindexpath *) Indexpath;

96.//Customizing the cell's edit mode

97.-(Uitableviewcelleditingstyle) TableView: (UITableView *) TableView Editingstyleforrowatindexpath: (Nsindexpath *) Indexpath

98.{

  1. return uitableviewcelleditingstyledelete;
  2. }
  3. Sets whether Tableviewcell can be moved
  4. -(BOOL) TableView: (uitableview*) TableView Canmoverowatindexpath: (Nsindexpath *) Indexpath;
  5. This method is called when the cell is moved
  6. -(void) TableView: (uitableview*) TableView Moverowatindexpath: (Nsindexpath *) Fromindexpath Toindexpath: (Nsindexpath *) Toindexpath {
  7. Swap the position of an array of two elements
  8. [_mutablearray ExchangeObjectAtIndex:fromIndexPath.row WithObjectAtIndex:toIndexPath.row];
  9. }
  10. Set the cell of the TableView as an editable state
  11. -(BOOL) TableView: (uitableview*) TableView Caneditrowatindexpath: (Nsindexpath *) Indexpath;
  12. Set the cell of the TableView as an editable state
  13. -(BOOL) TableView: (uitableview*) TableView Caneditrowatindexpath: (Nsindexpath *) Indexpath;
  14. Deletes the specified cell
  15. [TableView Deleterowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationfade];
  16. Cell Multiplexing Dequeuereusablecellwithidentifier
  17. static NSString *indentify = @ "Newcell";
  18. UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:indentify];
  19. if (cell = = nil) {
  20. Cell=[[uitableviewcell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:indentify];
  21. 1, register the ordinary class of cell
  22. [Self.tableview Registerclass:[uitableviewcell class] forcellreuseidentifier:@ "Newcell"];
  23. Newcell *cell = [TableView dequeuereusablecellwithidentifier:@ "Newcell" Forindexpath:indexpath];
  24. 2, Registered Xib cell
  25. uinib *nib = [uinib nibwithnibname:@ "Newcell" bundle:nil];
  26. [Self.tableview registernib:nib forcellreuseidentifier:@ "Newcell"];
  27. Newcell *cell = [TableView dequeuereusablecellwithidentifier:@ "Newcell" Forindexpath:indexpath];
  28. The story version is not allowed to register. In these three cases,
  29. The cell that is created by loading the Xib file should be used this way
  30. cell = [[[NSBundle Mainbundle] loadnibnamed:@ "Fontscell" owner:self Options:nil] lastobject];
  31. -(ID) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) Reuseidentifier;

Cooked with 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.