zoukankan      html  css  js  c++  java
  • tableView的基本使用(改良版)

    @interface ViewController ()<UITableViewDataSource, UITableViewDelegate>

    {

        int i;//用来计算接受通知的次数

    }

    @property(nonatomic,strong)UITableView * tableView;

    @end

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view.

         self.navigationController.navigationBarHidden = YES;

         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(通知要执行的方法) name:@"有新消息了" object:nil];

         self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 屏幕宽度, 屏幕高度 - 49) style:UITableViewStyleGrouped];

        self.tableView.bounces = NO;

        self.tableView.backgroundColor = 灰色;

        [self.view addSubview:self.tableView];

        self.tableView.delegate = self;

        self.tableView.dataSource = self;

        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

        self.tableView.sectionFooterHeight = 0;

        [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];//在这里注册一下,数据源方法中就不用加判断语句了,否则数据源方法得加上if(cell == nil){创建新的cell};

    }

    #pragma mark - UITableViewDataSource

    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

    {

        return 1;

    }

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

    {

        return 1;

        

    }

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

    {

        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];

        //-----为cell添加数据----

        cell.xxx = @"xxxxx";.....

        return cell;

    }

    #pragma mark UITableViewDelegate

    -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

        if (section == 0) {

            return 300 * 屏幕宽度/375.0 + 20;

        }

        return 0;

    }

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

    {

        if (条件一) {

        }else{

        }

    }

  • 相关阅读:
    力扣236题、235(二叉树最近公共祖先)
    力扣222题(完全二叉树的节点个数)
    力扣130题、990题(并查集算法)
    力扣855题(考场就座)
    力扣659题(分割数组为连续子数组)
    力扣435题(区间调度问题)
    【转】编程之:EXPORT_SYMBOL使用
    【转】shell工具之:常用shell脚本命令详细
    【转】vim工具命令之:添加行号和删除行号
    BUG之【虚拟机报错】:Centos出现 rm: cannot remove x: Read-only file system 的总结
  • 原文地址:https://www.cnblogs.com/isItOk/p/4784628.html
Copyright © 2011-2022 走看看