生活随笔
收集整理的这篇文章主要介绍了
IOS开发基础之UI基础的团购源码完整版本
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
IOS开发基础之UI基础的团购源码完整版本
#import "ViewController.h"
#import "CZGoods.h"
#import "CZGoodsCell.h"
#import "CZFooterView.h"
#import "CZHeaderView.h"@interface ViewController
()<UITableViewDataSource
,CZFooterViewDelegate
>@property(nonatomic
,strong
)NSMutableArray
*goods
;
@property (weak
, nonatomic
) IBOutlet UITableView
*tableView
;@end@implementation ViewController
- (UITableViewCell
*)tableView
:(UITableView
*)tableView cellForRowAtIndexPath
:(NSIndexPath
*)indexPath
{CZGoods
*model
= self.goods
[indexPath
.row
];
CZGoodsCell
*cell
= [CZGoodsCell goodsCellWithTableView
:tableView
];cell
.goods
= model
;return cell
;}- (BOOL
)prefersStatusBarHidden
{return YES
;
}
- (NSInteger
)tableView
:(UITableView
*)tableView numberOfRowsInSection
:(NSInteger
)section
{return self.goods
.count
;}- (NSMutableArray
*)goods
{if(_goods
==nil
){NSString
*path
= [[NSBundle mainBundle
] pathForResource
:@"tgs.plist" ofType
:nil
];NSArray
*arrayDict
= [NSArray arrayWithContentsOfFile
:path
];NSMutableArray
*attayModles
= [NSMutableArray array
];for(NSDictionary
*dict
in arrayDict
){CZGoods
*model
= [CZGoods goodsWithDict
:dict
];[attayModles addObject
:model
];}_goods
= attayModles
;}return _goods
;
}#pragma 代理方法
- (void)footerViewUpdateData
:(CZFooterView
*)footerView
{CZGoods
*model
=[[CZGoods alloc
] init
];model
.title
= @"驴肉火烧";model
.price
=@"6.0";model
.buyCount
= @"1234";model
.icon
= @"d40878ee9d97a53bd4b8778daa11d38d.png";[self.goods addObject
:model
];[self.tableView reloadData
];NSIndexPath
*idxPath
= [NSIndexPath indexPathForRow
:self.goods
.count
-1 inSection
:0];[self.tableView scrollToRowAtIndexPath
:idxPath atScrollPosition
:UITableViewScrollPositionTop animated
:YES
];}- (void)viewDidLoad
{[super viewDidLoad
];self.tableView
.rowHeight
= 60;
CZFooterView
*footerView
= [CZFooterView footerView
];footerView
.delegate
= self;self.tableView
.tableFooterView
= footerView
;
CZHeaderView
*headerView
= [CZHeaderView headerView
];self.tableView
.tableHeaderView
=headerView
;}@end
#import <Foundation/Foundation.h>NS_ASSUME_NONNULL_BEGIN
@interface CZGoods
: NSObject
@property(nonatomic
,copy
)NSString
*buyCount
;
@property(nonatomic
,copy
)NSString
*price
;
@property(nonatomic
,copy
)NSString
*title
;
@property(nonatomic
,copy
)NSString
*icon
;-(instancetype
)initWithDict
:(NSDictionary
*)dict
;
+(instancetype
)goodsWithDict
:(NSDictionary
*)dict
;@endNS_ASSUME_NONNULL_END
#import "CZGoods.h"@implementation CZGoods
-(instancetype
)initWithDict
:(NSDictionary
*)dict
{if(self=[super init
]){[self setValuesForKeysWithDictionary
:dict
];}return self;
}
+(instancetype
)goodsWithDict
:(NSDictionary
*)dict
{return [[self alloc
] initWithDict
:dict
];
}
@end
#import <UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN
@class CZGoods
;
@interface CZGoodsCell
: UITableViewCell
@property(nonatomic
,strong
)CZGoods
*goods
;+(instancetype
)goodsCellWithTableView
:(UITableView
*)tableView
;@endNS_ASSUME_NONNULL_END
#import "CZGoodsCell.h"
#import "CZGoods.h"
@interface CZGoodsCell()
@property (weak
, nonatomic
) IBOutlet UIImageView
*imgViewIcon
;@property (weak
, nonatomic
) IBOutlet UILabel
*lblTitle
;@property (weak
, nonatomic
) IBOutlet UILabel
*lblPrice
;@property (weak
, nonatomic
) IBOutlet UILabel
*lblBuyCount
;@end@implementation CZGoodsCell
+ (instancetype
)goodsCellWithTableView
:(UITableView
*)tableView
{static NSString
*ID
= @"goods_cell";CZGoodsCell
*cell
= [tableView dequeueReusableCellWithIdentifier
:ID
];if(cell
==nil
){cell
=[[[NSBundle mainBundle
] loadNibNamed
:@"CZGoodsCell" owner
:nil options
:nil
] firstObject
];}return cell
;
}- (void)setGoods
:(CZGoods
*)goods
{_goods
= goods
;self.imgViewIcon
.image
=[UIImage imageNamed
:goods
.icon
];self.lblTitle
.text
=goods
.title
;self.lblPrice
.text
=[NSString stringWithFormat
:@"¥ %@",goods
.price
];self.lblBuyCount
.text
=[NSString stringWithFormat
:@"%@ 人已购买",goods
.buyCount
];}- (void)awakeFromNib
{[super awakeFromNib
];
}- (void)setSelected
:(BOOL
)selected animated
:(BOOL
)animated
{[super setSelected
:selected animated
:animated
];
}@end
#import <UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN
@class CZFooterView
;@protocol CZFooterViewDelegate
<NSObject
>
@required
-(void)footerViewUpdateData
:(CZFooterView
*)footerView
;@end@interface CZFooterView
: UIView
@property(nonatomic
,weak
)id
<CZFooterViewDelegate
> delegate
;+(instancetype
)footerView
;@endNS_ASSUME_NONNULL_END
#import "CZFooterView.h"@interface CZFooterView()@property (weak
, nonatomic
) IBOutlet UIButton
*btnLoadMore
;@property (weak
, nonatomic
) IBOutlet CZFooterView
*watingView
;- (IBAction
)btnLoadMoreClick
;@end@implementation CZFooterView
- (IBAction
)btnLoadMoreClick
{self.btnLoadMore
.hidden
= YES
;self.watingView
.hidden
= NO
;dispatch_after(dispatch_time(DISPATCH_TIME_NOW
, (int64_t
)(1.0 * NSEC_PER_SEC
)), dispatch_get_main_queue(), ^{if([self.delegate respondsToSelector
:@selector(footerViewUpdateData
:)]){[self.delegate footerViewUpdateData
:self];}self.btnLoadMore
.hidden
= NO
;self.watingView
.hidden
= YES
;});}+(instancetype
)footerView
{CZFooterView
*footerView
= [[[NSBundle mainBundle
] loadNibNamed
:@"CZFooterView" owner
:nil options
:nil
] lastObject
];return footerView
;}@end
#import <UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN
@interface CZHeaderView
: UIView
+(instancetype
)headerView
;@endNS_ASSUME_NONNULL_END
#import "CZHeaderView.h"@interface CZHeaderView
()@property (weak
, nonatomic
) IBOutlet UIScrollView
*scrollView
;@end@implementation CZHeaderView
- (void)awakeFromNib
{}+(instancetype
)headerView
{CZHeaderView
*headerView
= [[[NSBundle mainBundle
] loadNibNamed
:@"CZHeaderView" owner
:nil options
:nil
] firstObject
];return headerView
;}
@end
需要源码的朋友请私聊我VX: Johnson_Swift
创作挑战赛新人创作奖励来咯,坚持创作打卡瓜分现金大奖
总结
以上是生活随笔为你收集整理的IOS开发基础之UI基础的团购源码完整版本的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。