zoukankan      html  css  js  c++  java
  • FirstApp,iphone开发学习总结2,简单的表

    首先在TableViewController.h中,将UIViewController改成UITableViewController(委托先不写),并创建一个数组:

    @interface TableViewController : UITableViewController{
        NSMutableArray *data;
    }

    在init方法中,我们初始化此表为分组表:

    - (id)init {
        self = [super initWithStyle:UITableViewStyleGrouped];//分组样式
        if (self) {
            [self setTitle:@"表格展示"];
            UIImage *img = [UIImage imageNamed:@""];
            [[self tabBarItem] setImage:img];
        }
        return self;
    }
    - (id)initWithStyle:(UITableViewStyle)style
    {
        return [self init];
    }

    在- (void)viewDidLoad中初始并实例化数组:

    data = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3", nil];

    设置分组数://不是分组表,可以忽略,默认为1.

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return [data count];
    }

    设置每组的行数:*必须实现//理解section的意思

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        if (section == 0) {
            return 1;
        }else if(section == 1){
            return 2;
        }else{
            return 3;
        }
    }

    设置每行的数据:*必须实现//理解标识符(Identifier)的意思

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

    最后在- (void)dealloc释放data:

    [data release];
  • 相关阅读:
    【唯星宠物】——CSS/BootStrap/Jquery爬坑之响应式首页
    layui table数据渲染页面+筛选医生+在筛选日期一条龙2
    layui table数据渲染页面+筛选医生+在筛选日期一条龙
    拿到数组逗号分隔在循环拿到里面的数据,最后DOM插入页面
    解决跨域请求的几种方式
    MUI下拉刷新
    Java集合(6):理解Map
    Java集合(5):理解Collection
    Java集合(4):未获支持的操作及UnsupportedOperationException
    Java集合(3):使用Abstract类
  • 原文地址:https://www.cnblogs.com/maxfong/p/2481924.html
Copyright © 2011-2022 走看看