[ios] tableview summary

1. Define tableview

1. Define dataSource & delegate

Select the tableview on the storyboard, and pull the dataSource & delegate to the small dots of the viewcontroller on the linker

2. Inherit <UITableViewDataSource, UITableViewDelegate> on the header file

3. Declare tableview: pull the tableview control on the stroryboard into .m

 

2. Use

1. Set the data source: There are two ways:

The first: fixed, existing: assignable in viewdidload

The second type: conditional trigger, later: refresh data through [self.tableviewname reloadData]

Because tableview will automatically call - (NSInteger)tableView(UITableView *)tableView numberOfRowsInSection:(NSInteger)section and other functions when the interface is entered

 

2. Method:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    _count = [_macArray count];
    NSLog(@"table view : %lu",(unsigned long)_count);
    return [_macArray count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellname = @"namecell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellname];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellname];
    }
    
    cell.textLabel.text = _macArray[indexPath.row];
    return cell;
}

 The first method, return the length of the array to determine the number of cells

The second method generates tableviewcell

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326392388&siteId=291194637