日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IOS第八天(1:UITableViewController团购,数据转模型,xib显示数据)

發布時間:2025/7/14 编程问答 13 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS第八天(1:UITableViewController团购,数据转模型,xib显示数据) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

******HMTg.h 模型數據?

#import <Foundation/Foundation.h>@interface HMTg : NSObject @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *icon; @property (nonatomic, copy) NSString *price; @property (nonatomic, copy) NSString *buyCount;- (instancetype)initWithDict:(NSDictionary *)dict; + (instancetype)tgWithDict:(NSDictionary *)dict;+ (NSArray *)tgs;@end

******HMTg.m?模型數據?

#import "HMTg.h"@implementation HMTg- (instancetype)initWithDict:(NSDictionary *)dict {self = [super init];if (self) {[self setValuesForKeysWithDictionary:dict];}return self; }+ (instancetype)tgWithDict:(NSDictionary *)dict {return [[self alloc] initWithDict:dict]; }+ (NSArray *)tgs {NSArray *array = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"tgs.plist" ofType:nil]];NSMutableArray *arrayM = [NSMutableArray array];for (NSDictionary *dict in array) {[arrayM addObject:[self tgWithDict:dict]];}return arrayM; }@end

*********cell的文件HMTgCell.h

#import <UIKit/UIKit.h>@interface HMTgCell : UITableViewCell @property (weak, nonatomic) IBOutlet UIImageView *iconView; @property (weak, nonatomic) IBOutlet UILabel *titleLabel; @property (weak, nonatomic) IBOutlet UILabel *priceLabel; @property (weak, nonatomic) IBOutlet UILabel *buyCountLabel; @end

****HMTgCell.m

#import "HMTgCell.h"@interface HMTgCell()@end@implementation HMTgCell- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];if (self) {// Initialization code }return self; }- (void)awakeFromNib {// Initialization code }- (void)setSelected:(BOOL)selected animated:(BOOL)animated {[super setSelected:selected animated:animated];// Configure the view for the selected state }@end

**********HMViewController.m

#import "HMViewController.h" #import "HMTg.h" #import "HMTgCell.h"@interface HMViewController () @property (nonatomic, strong) NSArray *tgs; @end@implementation HMViewController- (NSArray *)tgs {if (_tgs == nil) _tgs = [HMTg tgs];return _tgs; }- (void)viewDidLoad {[super viewDidLoad];self.tableView.rowHeight = 80;// 調整邊距,可以讓表格視圖讓開狀態欄self.tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0); }///** 隱藏狀態欄 */ //- (BOOL)prefersStatusBarHidden //{ // return YES; //}#pragma mark - 數據源方法 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {return self.tgs.count; }- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {// 1. 可重用標示符static NSString *ID = @"Cell";// 2. tableView查詢可重用CellHMTgCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];// 3. 如果沒有可重用cellif (cell == nil) { // cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];// 從XIB加載自定義視圖 cell = [[[NSBundle mainBundle] loadNibNamed:@"HMTgCell" owner:nil options:nil] lastObject];}// 4. 設置Cell內容// 1> 取出模型HMTg *tg = self.tgs[indexPath.row];// cell.textLabel.text = tg.title; // cell.imageView.image = [UIImage imageNamed:tg.icon]; // // cell.detailTextLabel.text = [NSString stringWithFormat:@"¥%@ 已有%@人購買", tg.price, tg.buyCount];cell.titleLabel.text = tg.title;cell.iconView.image = [UIImage imageNamed:tg.icon];cell.priceLabel.text = tg.price;cell.buyCountLabel.text = tg.buyCount;return cell; }@end

?

轉載于:https://www.cnblogs.com/ios-g/p/4710977.html

總結

以上是生活随笔為你收集整理的IOS第八天(1:UITableViewController团购,数据转模型,xib显示数据)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。