優(yōu)惠券功能總結(jié)
注:項(xiàng)目添加了優(yōu)惠券功能撰糠,在此總結(jié)經(jīng)驗(yàn)
界面主要是:UITableView
優(yōu)惠卷的類型有4種,其中3種是樣式相同辩昆,背景顏色不同阅酪,以下稱為A1,A2,A3。另一種稱為B汁针。
開始的時候我是打算就用一個UITableViewCell
類來完成這4種樣式的术辐。但是只能在拿到數(shù)據(jù)之后才能知道具體類型,所以我在給cell賦值數(shù)據(jù)的API里面創(chuàng)建布局控件施无。其中使用了CAGradientLayer
和CAShapeLayer
辉词。
出現(xiàn)了一個奇怪的顯示問題。
問題:在cell的數(shù)量較少猾骡,不能被tableView復(fù)用的時候瑞躺,顯示正常。在cell的數(shù)量較多兴想,tableView能復(fù)用cell的時候幢哨,子layer的路徑會出現(xiàn)變化
--
我并沒解決好這個問題。而是使用了另一個類來搭建B的樣式嫂便。
--
后來我想了一下嘱么,用一個類來做也可以,使用兩個注冊cellID。
在 UITableViewCell
的 - initWithStyle:reuseIdentifier:
方法中
根據(jù) cellID 來搭建不同的樣式曼振。
--
實(shí)現(xiàn)方法:
創(chuàng)建一個優(yōu)惠券基類 : CouponBaseCell
A樣式的優(yōu)惠券 : ACouponBaseCell : CouponBasseCell
B樣式的優(yōu)惠券 : BCouponBaseCell : CouponBaseCell
CouponBaseCell
聲明 優(yōu)惠券的相應(yīng)API
/// 給優(yōu)惠券數(shù)據(jù)
- (void)setCoponData:(CouponInfo *)data;
/// 設(shè)置優(yōu)惠券類型
- (void)setCoponType:(CouponType)type;
/// 設(shè)置優(yōu)惠券狀態(tài)
- (void)setCoponState:(CouponState)state;
聲明一個點(diǎn)擊優(yōu)惠券的協(xié)議 Protocol
CouponBaseCellDelegate
///點(diǎn)擊優(yōu)惠券
- (void)didSelecteCoupon:(CouponBaseCell *)copon;
CouponBaseCell
添加一個遵守CouponBaseCellDelegate
協(xié)議的 id 類型的屬性几迄。
@property(nonatomic, weak) id <CouponBaseCellDelegate>delegate;
ACouponBaseCell
和BCouponBaseCell
分別根據(jù)對應(yīng)的需求實(shí)現(xiàn)這些API