欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

自定義單元格-創(chuàng)新互聯(lián)

自定義單元格:三種方法

成都創(chuàng)新互聯(lián)于2013年創(chuàng)立,先為內(nèi)江等服務(wù)建站,內(nèi)江等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為內(nèi)江企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

方法一:向contentView添加子視圖

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

  [super viewDidLoad];

  // Do any additional setup after loading the view, typically from a nib.

  UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];

  //內(nèi)容下移64px

  tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);

  tableView.dataSource = self;

  tableView.delegate = self;

  //獲取數(shù)據(jù)

  NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Films" ofType:@"plist"];

  self.dataArray = [[NSArray alloc] initWithContentsOfFile:filePath];

  [self.view addSubview:tableView];

}

#pragma Mark -UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

  return self.dataArray.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

  NSDictionary *dic = [self.dataArray objectAtIndex:indexPath.row];

  NSString *identifier = @"MyCell";

  UITableViewCell *tableVC = [tableView dequeueReusableCellWithIdentifier:identifier];

  if (tableVC == nil) {

    tableVC = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

    //注意:控件的創(chuàng)建應(yīng)該跟在tableVC的初始化放在一起,確保tableVC當中只有自己創(chuàng)建的這一個控件,不會出現(xiàn)空間的疊加(共有)

    //添加圖片

    UIImageView *p_w_picpathView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 150, 180)];

    p_w_picpathView.tag = 100;

    [tableVC.contentView addSubview:p_w_picpathView];

    //添加電影名稱

    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(190, 10, 200, 40)];

    titleLabel.tag = 101;

    titleLabel.font = [UIFont boldSystemFontOfSize:16];

    titleLabel.textColor = [UIColor blueColor];

    [tableVC.contentView addSubview:titleLabel];

    //添加電影評分

    UILabel *ratingLabel = [[UILabel alloc] initWithFrame:CGRectMake(190, 60, 100, 40)];

    ratingLabel.tag = 102;

    ratingLabel.font = [UIFont boldSystemFontOfSize:14];

    ratingLabel.textColor = [UIColor cyanColor];

    [tableVC.contentView addSubview:ratingLabel];

    //添加電影的年份

    UILabel *yearLabel = [[UILabel alloc] initWithFrame:CGRectMake(190, 110, 100, 20)];

    yearLabel.tag = 103;

    yearLabel.font = [UIFont boldSystemFontOfSize:12];

    yearLabel.textColor = [UIColor orangeColor];

    [tableVC.contentView addSubview:yearLabel];

  }

  //對控件賦值應(yīng)該放在外面(特有)

  //圖片

  UIImageView *p_w_picpathView = (UIImageView *)[tableVC.contentView viewWithTag:100];

  p_w_picpathView.p_w_picpath = [UIImage p_w_picpathNamed:[dic objectForKey:@"p_w_picpath"]];

  //名字

  UILabel *titleLabel = (UILabel *)[tableVC.contentView viewWithTag:101];

  titleLabel.text = [NSString stringWithFormat:@"電影:%@",[dic objectForKey:@"title"]];

  //評分

  UILabel *ratingLabel = (UILabel *)[tableVC.contentView viewWithTag:102];

  ratingLabel.text = [NSString stringWithFormat:@"評分:%@",[dic objectForKey:@"rating"]];

  //年份

  UILabel *yearLabel = (UILabel *)[tableVC.contentView viewWithTag:103];

  yearLabel.text = [NSString stringWithFormat:@"年份:%@",[dic objectForKey:@"year"]];

  return tableVC;

}

#pragma Mark -UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

  return 200;

}

@end

方法二:先創(chuàng)建一個xib文件---(然后在xib上拖一個tableCell并設(shè)置大小---(在tableCell上拖需要的控件并設(shè)置控件的屬性和tag值-----(將xib文件中tableCell的identifier該為設(shè)置的identifier

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

  [super viewDidLoad];

  // Do any additional setup after loading the view, typically from a nib.

  UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];

  tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);

  tableView.delegate =self;

  tableView.dataSource = self;

  [self.view addSubview:tableView];

  //定制單元格的高度

  tableView.rowHeight = 200;

  //獲取數(shù)據(jù)源

  NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Films" ofType:@"plist"];

  self.dataArray = [NSArray arrayWithContentsOfFile:filePath];

}

#pragma mark -UITableViewDataSource

#pragma mark -UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

  return self.dataArray.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

  NSString *identifier = @"MyCell";

  UITableViewCell *tableVC = [tableView dequeueReusableCellWithIdentifier:identifier];

  if (tableVC == nil) {

    tableVC =[[[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:nil options:nil]lastObject];

  }

  NSDictionary *dic = self.dataArray[indexPath.row];

  //圖片

  UIImageView *p_w_picpathView = (UIImageView *)[tableVC.contentView viewWithTag:100];

  p_w_picpathView.p_w_picpath = [UIImage p_w_picpathNamed:[dic objectForKey:@"p_w_picpath"]];

  //電影名

  UILabel *titleLabel = (UILabel *)[tableVC.contentView viewWithTag:101];

  titleLabel.text = [NSString stringWithFormat:@"電影:%@",[dic objectForKey:@"title"]];

  //評分

  UILabel *ratingLabel = (UILabel *)[tableVC.contentView viewWithTag:102];

  ratingLabel.text = [NSString stringWithFormat:@"評分:%@",[dic objectForKey:@"rating"]];

  //年份

  UILabel *yearLabel = (UILabel *)[tableVC.contentView viewWithTag:103];

  yearLabel.text = [NSString stringWithFormat:@"年份:%@",[dic objectForKey:@"year"]];

  return tableVC;

}

@end

方法三:

(1)方法一:在storyboard文件中拖一個tableView,然后再拖一個tableCell并設(shè)置大小---(在tableCell上拖需要的控件并設(shè)置控件的屬性-----(建立一個類繼承于UITableViewCell,將各個控件在此文件中聲明并聲明一個字典(根據(jù)情況而定)接收ViewContoller中值-------(將storyboard文件中tableCell的identifier該為設(shè)置的identifier,并繼承于新建的文件。

主要代碼寫在聲明的字典的set方法中。

#import "ViewController.h"

#import "MovieTableViewCell.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

  [super viewDidLoad];

  // Do any additional setup after loading the view, typically from a nib.

  NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Films" ofType:@"plist"];

  self.dataArray = [NSArray arrayWithContentsOfFile:filePath];

}

#pragma mark -UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

  return self.dataArray.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

  //V(View)

  MovieTableViewCell *tableVC = [tableView dequeueReusableCellWithIdentifier:@"MyCell" forIndexPath:indexPath];

  //在控制器中,不應(yīng)該設(shè)置太多視圖自己需要顯示的內(nèi)容,控制器充當MVC架構(gòu)模式中的C,需要做的應(yīng)該啊hi把M------->V

  //M(Model)

  NSDictionary *dic = self.dataArray[indexPath.row];

  //dic-------->Cell

  tableVC.dataDic = dic;

  return tableVC;

}

@end

#import "MovieTableViewCell.h"

@implementation MovieTableViewCell

//當視圖從xib文件或者storyboard中加載時,走這個方法,相當于初始化方法

- (void)awakeFromNib {

  // Initialization code

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

  [super setSelected:selected animated:animated];

  // Configure the view for the selected state

}

-(void)setDataDic:(NSDictionary *)dataDic

{

  if (_dataDic != dataDic) {

    _dataDic = dataDic;

    //此時確保值能傳過來

    self.imgView.p_w_picpath = [UIImage p_w_picpathNamed:[self.dataDic objectForKey:@"p_w_picpath"]];

    self.titleLabel.text = [NSString stringWithFormat:@"電影:%@",[self.dataDic objectForKey:@"title"]];

    self.ratingLabel.text = [NSString stringWithFormat:@"評分:%@",[self.dataDic objectForKey:@"rating"]];

    self.yearLabel.text = [NSString stringWithFormat:@"年份:%@",[self.dataDic objectForKey:@"year"]];

  }

}

@end

(2)(此方法比較常用)方法二:建立一個類繼承于UITableViewCell和創(chuàng)建一個類MoviewModel繼承與NSObject-------(將各個控件在繼承于UITableViewCell文件中創(chuàng)建并聲明一個MovieModel接收-----(在ViewContoller文件中創(chuàng)建MovieModel,接收值。

#import "ViewController.h"

#import "MovieTableViewCell.h"

#import "MovieModel.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

  [super viewDidLoad];

  // Do any additional setup after loading the view, typically from a nib.

  UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];

  tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);

  tableView.delegate =self;

  tableView.dataSource = self;

  [self.view addSubview:tableView];

  tableView.rowHeight = 200;

  //獲取數(shù)據(jù)源

//   NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Films" ofType:@"plist"];

//   self.dataArray = [NSArray arrayWithContentsOfFile:filePath];

  //由原來的dataDic改為裝movieModel

  NSArray *dataArr = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Films" ofType:@"plist"]];

  NSMutableArray *mArray = [NSMutableArray array];

  for (NSDictionary *dic in dataArr) {

    NSString *title = [dic objectForKey:@"title"];

    NSString *p_w_picpathName = [dic objectForKey:@"p_w_picpath"];

    NSString *rating = [dic objectForKey:@"rating"];

    NSString *year = [dic objectForKey:@"year"];

    //將數(shù)據(jù)填充到movieModel

    MovieModel *model = [[MovieModel alloc] init];

    model.title = title;

    model.p_w_picpathName = p_w_picpathName;

    model.ratingLabel = rating;

    model.yearLabel = year;

    [mArray addObject:model];

  }

  self.dataArray = mArray;

}

#pragma mark -UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

  return self.dataArray.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

  NSString *identifier = @"MyCell";

  MovieTableViewCell *tableVC = [tableView dequeueReusableCellWithIdentifier:identifier];

  if (tableVC == nil) {

    tableVC = [[MovieTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

  }

//   NSDictionary *dic = self.dataArray[indexPath.row];

//   tableVC.dataDic = dic;

  tableVC.movieModel = self.dataArray[indexPath.row];

  return tableVC;

}

@end

#import "MovieTableViewCell.h"

@implementation MovieTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

  self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

  if (self != nil) {

    //........

    [self initViews];

  }

  return self;

}

- (void)awakeFromNib {

  // Initialization code

  [super awakeFromNib];

  [self initViews];

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

  [super setSelected:selected animated:animated];

  // Configure the view for the selected state

}

//- (void)setDataDic:(NSDictionary *)dataDic

//{

//   if (_dataDic != dataDic) {

//     _dataDic = dataDic;

//     //手動調(diào)動layoutSubviews

//     [self setNeedsLayout];

//   }

//}

//初始化自身的子視圖

- (void)initViews

{

  //添加圖片

  UIImageView *p_w_picpathView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 150, 180)];

  p_w_picpathView.tag = 100;

  [self.contentView addSubview:p_w_picpathView];

  //添加電影名稱

  UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(190, 10, 200, 40)];

  titleLabel.tag = 101;

  titleLabel.font = [UIFont boldSystemFontOfSize:16];

  titleLabel.textColor = [UIColor blueColor];

  [self.contentView addSubview:titleLabel];

  //添加電影評分

  UILabel *ratingLabel = [[UILabel alloc] initWithFrame:CGRectMake(190, 60, 100, 40)];

  ratingLabel.tag = 102;

  ratingLabel.font = [UIFont boldSystemFontOfSize:14];

  ratingLabel.textColor = [UIColor cyanColor];

  [self.contentView addSubview:ratingLabel];

  //添加電影的年份

  UILabel *yearLabel = [[UILabel alloc] initWithFrame:CGRectMake(190, 110, 100, 20)];

  yearLabel.tag = 103;

  yearLabel.font = [UIFont boldSystemFontOfSize:12];

  yearLabel.textColor = [UIColor orangeColor];

  [self.contentView addSubview:yearLabel];

}

-(void)setMovieModel:(MovieModel *)movieModel

{

  if (_movieModel != movieModel) {

    _movieModel = movieModel;

    [self setNeedsLayout];

  }

}

//當子視圖重新布局時需要調(diào)用的方法

- (void)layoutSubviews

{

  //一定注意(不可缺少)

  [super layoutSubviews];

  //圖片

  UIImageView *p_w_picpathView = (UIImageView *)[self.contentView viewWithTag:100];

//   p_w_picpathView.p_w_picpath = [UIImage p_w_picpathNamed:[self.dataDic objectForKey:@"p_w_picpath"]];

  p_w_picpathView.p_w_picpath = [UIImage p_w_picpathNamed:self.movieModel.p_w_picpathName];

  //名字

  UILabel *titleLabel = (UILabel *)[self.contentView viewWithTag:101];

//   titleLabel.text = [NSString stringWithFormat:@"電影:%@",[self.dataDic objectForKey:@"title"]];

  titleLabel.text = [NSString stringWithFormat:@"電影:%@",self.movieModel.title];

  //評分

  UILabel *ratingLabel = (UILabel *)[self.contentView viewWithTag:102];

//   ratingLabel.text = [NSString stringWithFormat:@"評分:%@",[self.dataDic objectForKey:@"rating"]];

  ratingLabel.text = [NSString stringWithFormat:@"評分:%@",self.movieModel.ratingLabel];

  //年份

  UILabel *yearLabel = (UILabel *)[self.contentView viewWithTag:103];

//   yearLabel.text = [NSString stringWithFormat:@"年份:%@",[self.dataDic objectForKey:@"year"]];

  yearLabel.text = [NSString stringWithFormat:@"年份:%@",self.movieModel.yearLabel];

}

@end

MovieModel.h文件

#import <Foundation/Foundation.h>

@interface MovieModel : NSObject

@property (nonatomic,copy)NSString *p_w_picpathName;

@property (nonatomic,copy)NSString *title;

@property (nonatomic,copy)NSString *rating;

@property (nonatomic,copy)NSString *year;

@end

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

新聞標題:自定義單元格-創(chuàng)新互聯(lián)
瀏覽地址:http://chinadenli.net/article22/cdjgcc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航軟件開發(fā)、建站公司企業(yè)網(wǎng)站制作、品牌網(wǎng)站設(shè)計、全網(wǎng)營銷推廣

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作
日韩三级黄色大片免费观看| 九九九热在线免费视频| 亚洲另类女同一二三区| 一区二区三区四区亚洲另类| 久久国产亚洲精品成人| 日本免费熟女一区二区三区| 精品日韩中文字幕视频在线| 日韩中文字幕欧美亚洲| 亚洲综合日韩精品欧美综合区| 日本人妻的诱惑在线观看| 国产精品推荐在线一区| 国产又粗又黄又爽又硬的| 草草视频福利在线观看| 国产中文字幕一二三区| 老熟妇2久久国内精品| 日韩欧美在线看一卡一卡| 国产午夜免费在线视频| 久久久精品区二区三区| 免费黄片视频美女一区| 国产亚洲欧美日韩国亚语| 亚洲视频一区二区久久久| 精品国自产拍天天青青草原 | 日本和亚洲的香蕉视频| 国产精品免费无遮挡不卡视频 | 日韩一级欧美一级久久| 人妻熟女中文字幕在线| 欧美黄色成人真人视频| 亚洲欧美日韩国产自拍| 欧美日韩在线视频一区| 久久黄片免费播放大全| 2019年国产最新视频| 绝望的校花花间淫事2| 亚洲国产综合久久天堂| 在线观看视频国产你懂的| 日韩人妻中文字幕精品| 国产又长又粗又爽免费视频| 少妇毛片一区二区三区| 色一情一乱一区二区三区码| 内射精子视频欧美一区二区| 国产欧美日韩精品一区二区| 精品伊人久久大香线蕉综合|