资讯

精准传达 • 有效沟通

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

关于ui中的表视图-创新互联

#import "ViewController.h"

创新互联公司专注于翁牛特企业网站建设,响应式网站开发,成都商城网站开发。翁牛特网站建设公司,为翁牛特等地区提供建站服务。全流程按需网站开发,专业设计,全程项目跟踪,创新互联公司专业和态度为您提供的服务

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

  [super viewDidLoad];

  self.data = [NSMutableArray arrayWithArray:[UIFont familyNames]];

  //设置表视图分割线风格没有分割线

  //_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

  //没有分割线

  //_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

  //设置分割线颜色,默认为灰色

  _tableView.separatorColor = [UIColor orangeColor];

  //设置分割线的偏移量

  //_tableView.separatorInset = UIEdgeInsetsMake(0, -50, 0, -50);

  //设置表视图的头部视图

  UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 160)];

  //创建按钮

  UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd];

  btn.frame = CGRectMake(100, 50, 100, 100);

  [headerView addSubview:btn];

  [btn addTarget:self action:@selector(btn_click:) forControlEvents:UIControlEventTouchUpInside];

  headerView.backgroundColor = [UIColor yellowColor];

  _tableView.tableHeaderView = headerView;

  //设置表视图的尾部视图

  UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 200)];

  footView.backgroundColor = [UIColor purpleColor];

  _tableView.tableFooterView = footView;

  //设置单元格的行高,默认为44,如果要动态的设置行高,需要在代理方法中实现

  //_tableView.rowHeight = 100;

}

- (void)btn_click:(UIButton *)btn{

  //点击按钮删除第一个元素

  [self.data removeObjectAtIndex:0];

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

  //[self.tableView reloadData];

  //把第五个元素改为华文琥珀

  //构建IndexPath

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

  //取到单元格

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

  tvc.textLabel.text = @"华文琥珀";

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

//  NSArray *cells = [self.tableView visibleCells];

//  for (UITableViewCell *cell in cells) {

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

//  }

//

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

//  NSArray *indexPaths = [self.tableView indexPathsForVisibleRows];

//  for (NSIndexPath *indexPath in indexPaths) {

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

//  }

//  //输出选中的单元格

//  NSArray *selecedRows = [self.tableView indexPathsForSelectedRows];

//  for (NSIndexPath *selectedRow in selecedRows) {

//    NSLog(@"%@",selectedRow);

//  }

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

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

  [self.tableView scrollToRowAtIndexPath:indexPath2 atScrollPosition:UITableViewScrollPositionTop animated:YES];

}

#pragma mark--UITableViewDataSource

//表视图的行数

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

  return self.data.count;

}

//单元格内容

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

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

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

  tvCell.textLabel.text = str;

  return tvCell;

}

//设置单元格的高度

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

  if (indexPath.row == 3) {

    return 80;

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

    return 100;

  }

  return 40;//无效,不会执行

}

- (void)didReceiveMemoryWarning {

  [super didReceiveMemoryWarning];

  // Dispose of any resources that can be recreated.

}

@end

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


新闻标题:关于ui中的表视图-创新互联
文章路径:http://cdkjz.cn/article/jicid.html
多年建站经验

多一份参考,总有益处

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

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

大客户专线   成都:13518219792   座机:028-86922220