@protocol
TRIPHotelXXXViewDelegate <NSObject>
- (
void
)actionA;
@end
@interface
TRIPHotelXXXView : UIView
@property
(nonatomic,weak) id <TRIPHotelXXXViewDelegate> delegate;
+ (instancetype)xxxView:(NSDictionary *)info width:(CGFloat)width;
@end
|
@implementation
TRIPHotelXXXView{
// 類變量
}
- (
void
)dealloc{
// 內存釋放
SafeSuperDealloc(
super
);
}
- (id)initWithFrame:(CGRect)frame{
self = [
super
initWithFrame:frame];
if
(self) {
// 變量初始化
}
return
self;
}
- (
void
)layoutSubviews{
[
super
layoutSubviews];
CGFloat y =
0.0
;
// 子View的佈局,y動態調整
// 更新自定義UI的高度
CGRect rect = self.frame;
rect.size.height = y;
self.frame = rect;
}
+ (instancetype)xxxView:(NSDictionary *)info width:(CGFloat)width;{
// 用view的數據及父view的寬度定義並初始化一個UI
TRIPHotelXXXView *view = [[TRIPHotelXXXView alloc] initWithFrame:CGRectMake(
0
,
0
, width,
0
)];
[view updateViewWithInfo:info];
return
view;
}
- (
void
)updateViewWithInfo:(NSDictionary *)info{
// view自己的數據填充
// 從新佈局子View
[self layoutSubviews];
}
#pragma mark - Action
- (
void
)onSomeActionHappened:(id)sender{
if
(_delegate && [_delegate respondsToSelector:
@selector
(actionA)]) {
[_delegate actionA];
}
}
|