#import "ZYSettingViewController.h"
//UITableView代理设置
@interface ZYSettingViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) NSArray *array;//数据
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end
static int const ImageMarginTop = 25;//设置页面图片距离上边距离
static NSString* const ID = @"settingCell";//Item复用
@implementation ZYSettingViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"设置";
self.view.backgroundColor = ZYCommonBgColor;
_array = [NSArray arrayWithObjects:@"版本更新",@"分享应用",@"用户反馈",@"关于我们", nil];//初始化数据
//设置底部
UIView *footerView = [[UIView alloc] init];
footerView.backgroundColor = [UIColor whiteColor];
[_tableView setTableFooterView:footerView];
//初始化imageView
UIImage *image=[UIImage imageNamed:@"icon_qr_jgz"];
CGFloat imageW = image.size.width;
UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake((ScreenWidth-imageW)/2, ImageMarginTop, imageW, image.size.height)];
imageView.image=image;
[footerView addSubview:imageView];
//初始化label
UILabel *label=[[UILabel alloc]init];
label.textColor = ZYTagBgColor;
label.text=@"QQ扫一扫或点我一键加群";
[label sizeToFit];
CGFloat labelW = label.frame.size.width;
CGFloat labelH = label.frame.size.height;
label.frame = CGRectMake((ScreenWidth-labelW)/2, CGRectGetMaxY(imageView.frame), labelW, labelH);
[footerView addSubview:label];
//加到tableView底部
footerView.frame = CGRectMake(0, 0, ScreenWidth, CGRectGetMaxY(label.frame)+ImageMarginTop);
}
#pragma mark 这一组里面有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [_array count];
}
#pragma mark 返回第indexPath这行对应的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if(cell==nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
}
cell.textLabel.text = [_array objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//右边箭头
return cell;
}
//在TableView上选中某个Cell会触发
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
IOS学习之UITableView
最新推荐文章于 2022-01-13 14:41:23 发布