资讯

精准传达 • 有效沟通

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

iOS中tableView的分类有哪些-创新互联

这篇文章主要介绍iOS中tableView的分类有哪些,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

目前成都创新互联已为1000+的企业提供了网站建设、域名、网站空间网站托管运营、企业网站设计、尉犁网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

大致分了一下,一个uitableview需要几个方法去实现, 创建一个tableivew,自定义一个cell,一个cell的模型,一个cell子控件的大小,复杂的话可以在加一个继承tableview的方法1般是3种或者4种,或者是5种。

#import "ViewController.h"

@interface XXTableiewCell : UITableViewCell

@end

const float XXTableiewCell_fontSize = 12;

@interface XXTableiewCell ()

@property (strong, nonatomic) UILabel * titleLabel;

@property (strong, nonatomic) UILabel * showTilleLable;

@end

@implementation XXTableiewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView{

  static NSString *cellID = @"cellId";

   XXTableiewCell * cell = [[XXTableiewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];

  return cell;

}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

  self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

  if(self){

    [self setViewUI];

  }

  return self;

}

- (void)setViewUI{

  _titleLabel = [[UILabel alloc] init];

  _titleLabel.font = [UIFont systemFontOfSize:XXTableiewCell_fontSize];

  _titleLabel.textColor = [UIColor grayColor];

  _titleLabel.textAlignment = NSTextAlignmentLeft;

  _titleLabel.backgroundColor = [UIColor clearColor];

  [self.contentView addSubview:_titleLabel];

  _showTilleLable = [[UILabel alloc] init];

  _showTilleLable.font = [UIFont systemFontOfSize:XXTableiewCell_fontSize];

  _showTilleLable.textColor = [UIColor grayColor];

  _showTilleLable.textAlignment = NSTextAlignmentLeft;

  _showTilleLable.backgroundColor = [UIColor clearColor];

  [self.contentView addSubview:_showTilleLable];

}

- (void)layoutSubviews{

  [super layoutSubviews];

  _titleLabel.frame = CGRectMake(10, 0, self.contentView.frame.size.width-20, 20);

  _showTilleLable.frame = CGRectMake(_titleLabel.frame.origin.x, _titleLabel.frame.size.height + _titleLabel.frame.origin.y + 5, _titleLabel.frame.size.width, _titleLabel.frame.size.height);

}

@end

@interface ViewController ()

@property (strong,nonatomic)NSMutableArray * resultArry;

@end

@implementation ViewController

- (void)viewDidLoad {

  [super viewDidLoad];

  _resultArry = [NSMutableArray arrayWithArray:[UIFont familyNames]];

  UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];

  tableView.dataSource = self;

  tableView.delegate = self;

  [self setExtraCellLineHidden:tableView];

  [self.view addSubview:tableView];

}

// 隐藏多余cell

-(void)setExtraCellLineHidden: (UITableView *)tableView

{

  UIView *view = [UIView new];

  view.backgroundColor = [UIColor clearColor];

  [tableView setTableFooterView:view];

}

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

{

  return _resultArry.count;

}

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

{

 XXTableiewCell * cell = [XXTableiewCell cellWithTableView:tableView];

  cell.titleLabel.text = [NSString stringWithFormat:@"%ld",(NSInteger)indexPath.row + 1];

  cell.showTilleLable.text = [NSString stringWithFormat:@"%@",_resultArry[indexPath.row]];

  return cell;

}

#pragma mark-设置每一组的高度

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

{

  return 50;

}

#pragma mark 设置选中处理方法

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

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

}

- (void)didReceiveMemoryWarning {

  [super didReceiveMemoryWarning];

  // Dispose of any resources that can be recreated.

}

以上是“iOS中tableView的分类有哪些”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!

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


当前名称:iOS中tableView的分类有哪些-创新互联
标题网址:http://cdkjz.cn/article/ddogcg.html
多年建站经验

多一份参考,总有益处

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

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

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