资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

OC中UITableView的属性用法-创新互联

//删除第一个元素

成都创新互联专业提供成都主机托管四川主机托管成都服务器托管四川服务器托管,支持按月付款!我们的承诺:贵族品质、平民价格,机房位于中国电信/网通/移动机房,服务器托管雅安服务有保障!

  [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;

}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前标题:OC中UITableView的属性用法-创新互联
网站链接:http://cdkjz.cn/article/dpgdpi.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220