IOS学习之UITableView

16 篇文章 0 订阅
#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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值