Knowledge Point Review-tableview display data common settings

Source: Internet
Author: User

  1. How to make TableView show data
    • Setting the data source object
  2. self.tableView.dataSource = self;
    • Data source object to comply with protocol
  3. @interface ViewController () <UITableViewDataSource>@end
    • Implementing a Data source method
  4. // 多少组数据- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;// 每一组有多少行数据- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;// 每一行显示什么内容- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;// 每一组的头部- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;// 每一组的尾部- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
    Common settings for TableView
    Set the height of each row of cells
    Self.tableView.rowHeight = 100;

    Set the height of each group of headers
    Self.tableView.sectionHeaderHeight = 50;

    Set the height of each set of tails
    Self.tableView.sectionFooterHeight = 50; --each line of the > set is fixed

    Set the split Line color
    Self.tableView.separatorColor = [UicolorRedcolor];
    Set the split line style
    Self.tableView.separatorStyle= Uitableviewcellseparatorstylenone;
    Setting the header control
    Self.tableView.tableHeaderView= [[Uiswitch alloc] init];
    Set footer controls
    Self.tableView.tableFooterView = [UIButtonButtonwithtype:uibuttontypecontactadd];

    Set the color of the index text on the right
    Self.tableView.sectionIndexColor = [UicolorRedcolor];
    Set the background color of the index text on the right
    Self.tableView.sectionIndexBackgroundColor = [UicolorBlackcolor];
  5.  Common settings for Tableviewcell


    Set the indicator style to the right
    Cell. accessorytype= Uitableviewcellaccessorydisclosureindicator;

    Set the indicator control to the right
    Cell. Accessoryview= [[Uiswitch alloc] init];

    Set the cell's selected style
    Cell. Selectionstyle= Uitableviewcellselectionstylenone;
    Backgroundview Priority > BackgroundColor

    Set Background color
    Cell. backgroundcolor = [UicolorRedcolor];

    //Set background view--(customizable background image)
    UIView*BG = [[UIViewalloc] init];
    BG. backgroundcolor = [UicolorBluecolor];
    Cell. Backgroundview= BG;

    Set the selected background view
    UIView*selectedbg = [[UIViewALLOC] init];
    selectedbg. backgroundcolor = [UicolorPurplecolor];
    Cell. Selectedbackgroundview= selectedbg;

    Proxy method
/**
* Called when a row is selected (click)
*/
-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath
{
Xmgwine *wine = Self.winearray[indexpath.row];
NSLog (@ "clicked:%@", wine.name);
NSLog (@ "Selected:%zd", Indexpath.row);
}

/**
* Called when a row is unchecked
*/
-(void) TableView: (UITableView *) TableView Diddeselectrowatindexpath: (Nsindexpath *) Indexpath
{
NSLog (@ "Unchecked:%zd", Indexpath.row);
}/** * In each set of header settings control */-(UIView *) TableView: (UITableView *) TableView viewforheaderinsection: (nsinteger) Section
{
return [UIButton Buttonwithtype:uibuttontypeinfodark];
}/** * Set Control */-(UIView *) at the tail of each group TableView: (UITableView *) TableView viewforfooterinsection: (nsinteger) Section
{
return [[Uiswitch alloc] init];
}/** * can be judged by different groups setting different heights */-(cgfloat) TableView: (UITableView *) TableView heightforheaderinsection: (nsinteger) Section
{
if (section = = 0) return 20;
if (section = = 1) return 50;} /** * Returns the height of each cell (set different heights) */
-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath
{
if (indexpath.row% 2 = = 0) {
return 50;
} else {
return 100;
}}

Knowledge Point Review-tableview display data common settings

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.