美文网首页
tableview 常用函数

tableview 常用函数

作者: LuckTime | 来源:发表于2016-06-20 16:15 被阅读86次

/**

  • 返回组数
    */
    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    return 3;
    }

/**

  • 每个section 加载多少个单元。
    */
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {

    return 3;

}

/**

  • 每个cell显示的内容
    */
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if(indexPath.section == 0)
    {
    UITableViewCell * cell1 = [[UITableViewCell alloc]init];
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone ;
    cell1.textLabel.font = [UIFont systemFontOfSize:12];
    cell1.backgroundColor = [UIColor whiteColor];
    if(indexPath.row == 0)
    {

    cell1.textLabel.text = @"玩耍记录";
    return cell1;
    
    }
    

// if(indexPath.row == 1)
else
{

        cell1.textLabel.text = @"主要内容:两个人之间玩耍的记录,比如什么游戏,谁赢了,有什么惩罚";
        return cell1;

    }

}
else if(indexPath.section == 1) {
    UITableViewCell * cell1 = [[UITableViewCell alloc]init];
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone ;

    cell1.textLabel.font = [UIFont systemFontOfSize:12];
    cell1.backgroundColor = [UIColor whiteColor];
    if(indexPath.row == 0)
    {

        cell1.textLabel.text = @"日志报";
        return cell1;

    }

// if(indexPath.row == 1)
else
{

        cell1.textLabel.text = @"主要内容:主要包括纪念日,约定,承诺";
        return cell1;

    }
}

else if(indexPath.section == 2) {
    UITableViewCell * cell1 = [[UITableViewCell alloc]init];
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone ;

    cell1.textLabel.font = [UIFont systemFontOfSize:12];
    cell1.backgroundColor = [UIColor whiteColor];
    if(indexPath.row == 0)
    {

        cell1.textLabel.text = @"反悔墙";
        return cell1;

    }
    else

// if(indexPath.row == 1)
{

        cell1.textLabel.text = @"主要内容:主要用于承认错误";
        return cell1;

    }

}

    return nil;

}

/**

  • 监听cell
    */
    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if (indexPath.section == 0) {
    if (indexPath.row == 1) {
    MyLog(@"主要内容:两个人之间玩耍的记录,比如什么游戏,谁赢了,有什么惩罚");
    }

    }

    else if (indexPath.section == 1) {
    if (indexPath.row == 1) {
    MyLog(@"主要内容:主要包括纪念日,约定,承诺");

    }
    

    }

    else if (indexPath.section == 2) {
    if (indexPath.row == 1) {
    MyLog(@"主要内容:主要用于承认错误");
    }

    }

}

/**

  • 设置每个Cell的高度
    */
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if (indexPath.section == 0) {
    if (indexPath.row == 0) {
    return 10;
    }
    else
    {
    return 100;

    }
    

    }

    else if (indexPath.section == 1) {
    if (indexPath.row == 0) {
    return 10;
    }
    else
    {
    return 100;

    }
    

    }

    else if (indexPath.section == 2) {
    if (indexPath.row == 0) {
    return 10;
    }
    else
    {
    return 100;

    }
    

    }

    else
    {
     return 0;
    }
    

}

//==========================================

===========================================

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    return 5;
    }

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    static NSString *ID = @"test";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"Demo -- %ld", indexPath.row];
    return cell;
    }

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    NSString *demoClassString = [NSString stringWithFormat:@"DemoVC%ld", indexPath.row];

    [self.navigationController pushViewController:[NSClassFromString(demoClassString) new] animated:YES];
    }

相关文章

网友评论

      本文标题:tableview 常用函数

      本文链接:https://www.haomeiwen.com/subject/bvovdttx.html