zoukankan      html  css  js  c++  java
  • IOS> TableView 用法

    1.在视图上创建TableView( 拖控件),为ViewController创建UITableView属性(链接至TableView)和NSArray属性(存储数据)

    ViewController.h
    @property (strong, nonatomic) NSArray *list;
    @property (weak, nonatomic) IBOutlet UITableView *tableView;

    2.为UIViewController实现UITableViewDelegate,UITableViewDataSource两个协议

    ViewController.h
    @interface ViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>
    @property (strong, nonatomic) NSArray *list;
    @property (weak, nonatomic) IBOutlet UITableView *tableView;
    @end

    3.同步属性

    ViewController.c
    @synthesize list = _list;


    4.设置tableview数据源的数据,显示代理 以及显示区域等.

    ViewController.c
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        NSArray *array = [[NSArray alloc] initWithObjects:@"美国", @"菲律宾",
                          @"黄岩岛", @"中国", @"泰国", @"越南", @"老挝", @"日本" ,nil];
        self.list = array;
        [self.tableView setFrame:CGRectMake(0, 0, 320, 420)];
        [self.tableView setDataSource:self];
        [self.tableView setDelegate:self];
        
    }


    5.绘制表格单元

    ViewController.c
    //Draw tableview cell
    -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        static NSString *TableSampleIdentifier = @"TableSampleIdentifier";
        
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:TableSampleIdentifier];
        
        if(cell == nil){
            cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:TableSampleIdentifier];
        }
        
        NSUInteger row = [indexPath row];
        
        cell.textLabel.text=[self.list objectAtIndex:row];
        
        return cell;
    }
    
    -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return [self.list count];
    }


  • 相关阅读:
    Spark开发环境搭建(IDEA、Scala、SVN、SBT)
    Spark源码系列:RDD repartition、coalesce 对比
    Scala:类和对象
    申请MS的FastCounter
    code generation part1some OOrelated topic! not completed
    [book]ADO.NET实用指南
    如果FC能把blog的WEB VIEW与AGG VIEW统计起来就方便多了
    Dell 1704
    O'Reilly .NET Framework Essentials, 2nd Edition
    单用户blog系统(一)
  • 原文地址:https://www.cnblogs.com/fortunely/p/4472174.html
Copyright © 2011-2022 走看看