IOS--UI 电影列表纯代码

这篇博客记录了作者在iOS开发中构建电影列表UI的过程,从使用UITabBarController开始,逐步创建UITableView,设计自定义UITableViewCell,设置model类,并讨论了布局、图片格式注意事项以及界面设计。虽然界面设计有待改进,但作者从中加深了对数据剥离、布局、继承和模型赋值的理解。
摘要由CSDN通过智能技术生成

还没写完就发现 自己之前的知识太多的不牢固 很多东西需要翻之前的代码
1.布局 因为是可以在多个界面切换 界面之前也是平级关系 我们就需要建立一个 UITabBarController 来控制 然后在 建立所需要的界面 继承 UITableViewController 我对于这个继承谁 不是特别的擅长
首先是电影列表 我的思想是:先布出主界面并有标签栏控制–>添加所需要 label 和 image 再利用 mode 赋值

//我直接把我所需要的界面都添加到了标签控制器 以后这个文件几乎没有用了
#import "RootViewController.h"
#import "MineViewController.h"
#import "HuodongViewController.h"
#import "MovieTableViewController.h"
@interface RootViewController ()<UITabBarControllerDelegate>

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configureBarController];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)configureBarController{
    //    创建单视图控制器 然后加入标签控制器
    //    Movie


    MovieTableViewController *movieTVC = [[MovieTableViewController alloc]init];
    UINavigationController *movieTNV =[[UINavigationController alloc]initWithRootViewController:movieTVC];
    movieTVC.title =@" 电影列表";
    movieTNV.tabBarItem.image =[ UIImage imageNamed:@"45-movie1"];


    //    活动
    HuodongViewController *huodongVC =[[HuodongViewController alloc]init];
    UINavigationController *huodongNV =[[UINavigationController alloc]initWithRootViewController:huodongVC];
    huodongVC.title = @"活动";
    huodongNV.tabBarItem.image =[UIImage  imageNamed:@"12-eye"];

    //    Mine
    MineViewController *mineVC =[[MineViewController alloc]init
                                 ];
    UINavigationController *mineNC =[[UINavigationController alloc]initWithRootViewController:mineVC];
    mineVC.title=@"我的";
    mineNC.tabBarItem.image =[UIImage imageNamed:@"51-outlet"];


//    //  建立标签控制器  为什么这样就是错了?
//这个地方我犯了一个错误 我又建立了一个继承 UITabBarController 的对象 那么这个对象和这个文件不是一个空间 就算是后面我将数组添加到里面 我的模拟机也是无法显示我布局好的一些 因为在 Appdelegate.m 文件里面的设定的根视图控制器是 RootViewController 
//    UITabBarController *barC =[[UITabBarController alloc]init];
    NSArray *controller =@[movieTNV,huodongNV,mineNC];
  self.viewControllers = controller;
    //    配置标签栏的颜色

    self.tabBar.barTintColor =[UIColor whiteColor];


    //   被选中的 button 颜色
    self.tabBar.tintColor = [UIColor cyanColor];

    //  配置代理属性
    self.delegate =self;


    [movieTVC release];
    [movieTNV release];
    [mineVC release];
    [mineNC release];
    [huodongVC release];
    [huodongNV release];

}

② 为你的 movie 添加你需要的 cell 建立新的继承 UITableViewCell 的文件

.h
#import <UIKit/UIKit.h>
@class MovieListMode;
@interface MovieListTableViewCell : UITableViewCell
@property (nonatomic,retain)UILabel *rating;
@property (nonatomic,retain)UILabel *pubdate;
@property (nonatomic,retain)UILabel *title;
@property (nonatomic,retain)UIImageView *viewBig;
@property (nonatomic,retain)UIImageView *viewL;
@property (nonatomic,retain)MovieListMode *listMode;
@end

#import "MovieListTableViewCell.h"
#import "MovieListMode.h"
@implementation MovieListTableViewCell
- (void)dealloc
{
    [_pubdate release];
    [_title release];
    [_rating release];
    [_viewBig release];
    [_viewL release];
    [super dealloc];
}
//重写父类方法
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self p_setUp];

    }return self;
}
//重写setting 为什么呢? 我们需要赋值 而这些值 系统没有 所以要重新写
-(void)setListMode:(MovieListMode *)listMode{
    if (_listMode !=listMode) {
        [_listMode release];
        _listMode = [listMode retain];

    }
    self.title.text =listMode.title;
    self.pubdate.text =listMode.pubdate;
    self.rating.text = listMode.rating;



}
 // 这就是布局  
-(void)p_setUp{
    //底图
    self.viewBig =[[UIImageView alloc]initWithFrame:CGRectMake(0, 10, 310, 130)];
    self.viewBig.image =[UIImage imageNamed:@"bg_eventlistcell"];
    [self.contentView addSubview:self.viewBig];
    [self.viewBig release];
//    海报
    self.viewL =[[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.viewBig.frame)+5, CGRectGetMinY(self.viewBig.frame), CGRectGetWidth(self.viewBig.frame)/3, CGRectGetHeight(self.viewBig.frame)-20)];
    self.viewL.image =[UIImage imageNamed:@"picholder"];
    [self.viewBig  addSubview:self.viewL];
    [self.viewL release];

//    title
    self.title = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.viewL.frame)+10, CGRectGetMinY(self.viewL.frame)+15, CGRectGetWidth(self.viewBig.frame)/2, CGRectGetHeight(self.viewL.frame)/4)];
//    self.title.backgroundColor =[UIColor whiteColor];
    [self.contentView addSubview: self.title];
    [self.title release];

//    等级
    self.rating = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.title.frame), CGRectGetMaxY(self.title.frame)+10, CGRectGetWidth(self.title.frame), CGRectGetHeight(self.title.frame))];
//    self.rating.backgroundColor =[UIColor whiteColor];
    [self.contentView addSubview:self.rating];
    [self.rating release];

//    上映时间
    self.pubdate =[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.ti
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值