bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

自定義單元格-創新互聯

自定義單元格:三種方法

成都創新互聯于2013年創立,先為內江等服務建站,內江等地企業,進行企業商務咨詢服務。為內江企業網站制作PC+手機+微官網三網同步一站式服務解決您的所有建站問題。

方法一:向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];

  //內容下移64px

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

  tableView.dataSource = self;

  tableView.delegate = self;

  //獲取數據

  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];

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

    //添加圖片

    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];

  }

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

  //圖片

  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

方法二:先創建一個xib文件---(然后在xib上拖一個tableCell并設置大小---(在tableCell上拖需要的控件并設置控件的屬性和tag值-----(將xib文件中tableCell的identifier該為設置的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;

  //獲取數據源

  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并設置大小---(在tableCell上拖需要的控件并設置控件的屬性-----(建立一個類繼承于UITableViewCell,將各個控件在此文件中聲明并聲明一個字典(根據情況而定)接收ViewContoller中值-------(將storyboard文件中tableCell的identifier該為設置的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];

  //在控制器中,不應該設置太多視圖自己需要顯示的內容,控制器充當MVC架構模式中的C,需要做的應該啊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和創建一個類MoviewModel繼承與NSObject-------(將各個控件在繼承于UITableViewCell文件中創建并聲明一個MovieModel接收-----(在ViewContoller文件中創建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;

  //獲取數據源

//   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"];

    //將數據填充到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;

//     //手動調動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];

  }

}

//當子視圖重新布局時需要調用的方法

- (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

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

新聞標題:自定義單元格-創新互聯
瀏覽地址:http://vcdvsql.cn/article22/cdjgcc.html

成都網站建設公司_創新互聯,為您提供網站導航、軟件開發、建站公司、企業網站制作品牌網站設計全網營銷推廣

廣告

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

外貿網站制作