優(yōu)惠券功能總結(jié)
注:項目添加了優(yōu)惠券功能,在此總結(jié)經(jīng)驗
界面主要是: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 來搭建不同的樣式。
--
實現(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;
聲明一個點擊優(yōu)惠券的協(xié)議 Protocol
CouponBaseCellDelegate
///點擊優(yōu)惠券
- (void)didSelecteCoupon:(CouponBaseCell *)copon;
CouponBaseCell 添加一個遵守CouponBaseCellDelegate協(xié)議的 id 類型的屬性。
@property(nonatomic, weak) id <CouponBaseCellDelegate>delegate;
ACouponBaseCell和BCouponBaseCell分別根據(jù)對應(yīng)的需求實現(xiàn)這些API