In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the classification of tableView in iOS, which is very detailed and has a certain reference value. Friends who are interested must read it!
Roughly divided, a uitableview needs several methods to implement, create a tableivew, customize a cell, a cell model, a cell sub-control size, complex can be added to inherit tableview method 1 is 3 or 4, or 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]
}
/ / hide excess 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- sets the height of each group
-(CGFloat) tableView: (UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath
{
Return 50
}
# how to select pragma mark settings
-(void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
NSLog (@ "% ld", indexPath.row + 1)
}
-(void) didReceiveMemoryWarning {
[super didReceiveMemoryWarning]
/ / Dispose of any resources that can be recreated.
}
The above is all the content of the article "what are the categories of tableView in iOS". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.