IOS UI Learning UITableView-----Uitableviewdatasource

Source: Internet
Author: User

UITableView derived from Uiscrollview

The UITableView structure is as follows:

The background is a scrolling view, with each horizontal table called the cell (UITableViewCell)

each cell can store data or accept selected events .

When we select a cell, we can drop down the list, a new page can be launched

Select multiple cells in edit mode, you can delete batches and so on.

Member variables

1 {2     UITableView *  _tablev; 3     Nsmutablearray * _dataarr; 4     Uisearchcontroller * _search; 5     Nsmutablearray * _selectcell; 6 }

UITableView Creation (written in method, can be called with self)

-(void) createtableview{    _tablev = [[UITableView alloc] Initwithframe:cgrectmake (0, 0, [UIScreen mainscreen]. Bounds.size.width, [UIScreen mainscreen].bounds.size.height-64) style:uitableviewstylegrouped];    Set UITableView style  two styles    /*     uitableviewstyleplain,     uitableviewstylegrouped     *    //Set Agent    _tablev.delegate = self;    _tablev.datasource = self;        _tablev.separatorstyle = Uitableviewcellseparatorstylesingleline;        [Self.view Addsubview:_tablev];}

Uitableviewdatasource protocol method

Set UITableView cell (required)

-(uitableviewcell*) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{    //re-locator    static NSString * str = @ "cell";    Remove the cell in the queue    UITableViewCell * cell = [TableView dequeuereusablecellwithidentifier:str];    If the cell is null, a new cell    if (!cell) {        cell = [[UITableViewCell alloc] Initwithstyle is created: Uitableviewcellstyledefault reuseidentifier:str];    }    Cell.textLabel.text = _dataarr[indexpath.row];    return cell;}

  

Set the number of cells for the UITableView partition (section) (required)

-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{    //return [[_dataarr Objectatindex:section] count];    return _dataarr.count;}

Set the number of UITableView partitions (sections) (optional)

-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView;              Default is 1 if not implemented{    return 1;}

 

Set UITableView title header (optional)

-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) section{    return @ "title";}

  

Set UITableView title footer (optional)

-(NSString *) TableView: (UITableView *) TableView titleforfooterinsection: (nsinteger) section{    return @ "footer Title ";}

  

Set UITableView title footer (optional)

IOS UI Learning UITableView-----Uitableviewdatasource

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.