delegate and datasource methods for UITableView

后端 未结 12 1640
礼貌的吻别
礼貌的吻别 2020-12-13 00:50

Can anyone list delegate methods and data source methods for UITableView?

Are delegates and data sources methods are same for UITableView?<

相关标签:
12条回答
  • 2020-12-13 01:44

    List them?? No they are not same.. Look at documentation.. http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html

    http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html

    Datasource methods are used to generate tableView cells,header and footer before they are displaying..Delegate methods provide information about these cells, header and footer along with other user action handlers like cell selection and edit..

    0 讨论(0)
  • 2020-12-13 01:48

    UITableViewDelegate Protocol Reference

    0 讨论(0)
  • 2020-12-13 01:49

    Go to the link, it will describe about all the basics of UITableView.

    Primary Methods of UITableView are:

    – tableView:cellForRowAtIndexPath: // required method

    – tableView:numberOfRowsInSection: // required method

    – numberOfSectionsInTableView:
    
    – sectionIndexTitlesForTableView:
    
    – tableView:sectionForSectionIndexTitle:atIndex:
    
    – tableView:titleForHeaderInSection:
    
    – tableView:titleForFooterInSection:
    

    The required one are those whom you must have to include in the code. Don't forget to link the Table delegate and datasource with File Owner.

    0 讨论(0)
  • 2020-12-13 01:51

    Data Source Method:

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{}
    

    and

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{}
    

    Delegate method:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{}
    
    
    
    - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{}
    

    This are the main methods which we use to make table view work. Apart from this there are lots of method. Read UITableView Delegate and Datasource documentation to know more methods and its working.

    0 讨论(0)
  • 2020-12-13 01:54
    #pragma mark Tableview Delegate Method
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;    //count of section
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return 1;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView
             cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:@"TableviewCell"];
    
        UILabel *lbldescription = (UILabel *)[cell viewWithTag:1];
    
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.backgroundColor=[UIColor clearColor];
        return cell;
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
    {
    }
    
    -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
        return UITableViewAutomaticDimension;
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        return UITableViewAutomaticDimension;
    }
    
    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
        UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:@"TableviewCell_Header"];
    
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.backgroundColor=[UIColor whiteColor];
    
        return cell;
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {
        return 100;
    }
    
    0 讨论(0)
  • 2020-12-13 01:55

    Let me try to explain you in a simple way, the method I used to understand. Delegates simply keeps track of stuff that is done or the actions performed on the cell. While DataSource provides you with the functions that define how the table will look like.

    With that being said functions for delegates are:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{}
    
    • (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{}

    and DataSource

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{}
    

    and

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{}

    0 讨论(0)
提交回复
热议问题