@interface <#类名#> ()<UITableViewDelegate, UITableViewDataSource>
@property (strong, nonatomic) UITableView *tableView;
@property (strong, nonatomic) NSMutableArray<__kindof NSDictionary *> *tableViewArr;
@end
static NSString *<#类名#>CellID = @"<#类名#>Cell";
@implementation <#类名#>
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
// Do any additional setup after loading the view, typically from a nib.
self.navigationController.view.backgroundColor = [UIColor whiteColor];
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
self.navigationItem.title = @"<#此类的title#>";
[self setupTableViewArray];
[self settingTableViewWay];
}
/**
设置tableView的数据源
*/
- (void)setupTableViewArray {
self.tableViewArr = [NSMutableArray arrayWithCapacity:0];
[_tableViewArr addObject:@{@"class":@"<#要push过去的类名#>", @"title":@"<#push过去的类的title#>", @"details":@"<#push类的细节描述#>"}];
}
/**
设置tableView
*/
- (void)settingTableViewWay {
self.tableView = [[UITableView alloc] init];
[self.view addSubview:_tableView];
self.tableView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1 constant:0]];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.rowHeight = 50;
self.tableView.separatorColor = [UIColor orangeColor];//分隔线的颜色
self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);//分隔线间距(上, 左, 下, 右)
<#//不使用注册方式的cell#>[_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:<#类名#>CellID];
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
#pragma mark - UITableViewDataSource
/**
返回section的row
*/
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _tableViewArr.count;
}
/**
返回indexPath的cell
*/
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
<#//不使用注册方式的cell#>UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#类名#>CellID forIndexPath:indexPath];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#类名#>CellID];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:<#类名#>CellID];
}
cell.textLabel.text = [[_tableViewArr objectAtIndex:indexPath.row] objectForKey:@"title"];
cell.detailTextLabel.text = [[_tableViewArr objectAtIndex:indexPath.row] objectForKey:@"details"];
return cell;
}
#pragma mark - UITableViewDelegate
/**
cell的点击事件
*/
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *wayString = @"push";
if ([wayString isEqualToString:@"push"]) {
NSString *classString = [[_tableViewArr objectAtIndex:indexPath.row] objectForKey:@"class"];
NSString *titleString = [[_tableViewArr objectAtIndex:indexPath.row] objectForKey:@"title"];
Class tempClass = NSClassFromString(classString);
UIViewController *vc = [[tempClass alloc] init];
vc.view.backgroundColor = [UIColor whiteColor];
vc.navigationItem.title = titleString;
<#//不隐藏标签栏#>vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
} else if ([wayString isEqualToString:@"方法"]) {
NSString *selString = [NSString stringWithFormat:@"selectRowAtIndexPath%zd", indexPath.row];
SEL selector = NSSelectorFromString(selString);
IMP imp = [self methodForSelector:selector];
void (*func)(id, SEL) = (void (*)(id,SEL))imp;
func(self,selector);
} else {
}
}
- (void)selectRowAtIndexPath<#row#> {
}
@end
UITableView代码块
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 前言 一直以来我都不太习惯于UITableView的使用方式,因为只要是用tableview的控制器在调试代码的时...
- 普通代码块:在方法或语句中出现的{}就称为普通代码块。普通代码块和一般的语句执行顺序由他们在代码中出现的次序决定-...
- 1、概念 普通代码块:在方法或语句中出现的{}就称为普通代码块。普通代码块和一般的语句执行顺序由他们在代码中出现的...
- 例子 以引用Markdown的数学公式为例。 预览: 这是个数学公式,但是想打出源代码(比如说想介绍一下这个代码的...
- 静态代码块 1、格式 2、执行时间 静态代码块在类被加载的时候运行,且只执行一次,优先于任何代码块及构造函数。多个...