温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

OC中UITableView的属性用法

发布时间:2020-08-02 09:57:47 来源:网络 阅读:465 作者:ladispartion1 栏目:开发技术


    //删除第一个元素

    [self.data removeObjectAtIndex:0];

    

    //刷新表视图---重新执行数据源方法和代理方法

    [self.tableView reloadData];

    

    

    //把第2个单元格的内容改为呵呵

    //构建IndexPath

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2 inSection:0];

    //取到单元格

    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

    cell.textLabel.text = @"呵呵";

    

    //输出在屏幕上显示的单元格的内容

    NSArray *cells = [self.tableView visibleCells];

    for (UITableViewCell *cell in cells) {

        NSLog(@"%@", cell.textLabel.text);

    }

    

    //输出在屏幕上显示的单元格的下标

    NSArray *indexPaths = [self.tableView indexPathsForVisibleRows];

    for (NSIndexPath *indexPath in indexPaths) {

        NSLog(@"%ld", indexPath.row);

    }

    

    

    // 滑动到指定的位置,可以配置动画

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:10 inSection:0];

    [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:true];


}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


#pragma mark -UITableViewDataSource

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

{

    return self.data.count;

}




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

{

    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];

    NSString *fontName = self.data[indexPath.row];

    cell.textLabel.text = fontName;

//    cell.textLabel.font = [UIFont fontWithName:fontName size:20];

    

    return cell;

}


//设置section头部、尾部视图的高度

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

{

    return 80;

}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

    return 80;

}

//自定义头标题

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 200)];

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, 100, 30)];

    label.text = @"123213";

    label.backgroundColor = [UIColor whiteColor];

    [view addSubview:label];

    NSLog(@"%@:",view);

    view.backgroundColor = [UIColor blueColor];

    return view;

}

//设置单元格的高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (indexPath.row == 0) {

        return 100;

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

        return 200;

    }

    return 44;

}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI