這篇文章主要介紹iOS中tableView的分類有哪些,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
大致分了一下,一個uitableview需要幾個方法去實現(xiàn), 創(chuàng)建一個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 () <UITableViewDataSource, UITableViewDelegate>
@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的分類有哪些”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
新聞名稱:iOS中tableView的分類有哪些-創(chuàng)新互聯(lián)
路徑分享:http://www.rwnh.cn/article26/ddogcg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設、電子商務、用戶體驗、營銷型網(wǎng)站建設、關鍵詞優(yōu)化、外貿網(wǎng)站建設
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內容