29,027
社区成员
发帖
与我相关
我的任务
分享
#import "ClickTv.h"
@implementation ClickTv
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 66.0f;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *IDENTIFIER = @"CLICK_TV_CELL";
ClickTvCell *cell = [tableView dequeueReusableCellWithIdentifier:IDENTIFIER];
if(nil == cell)
cell = [[[ClickTvCell alloc] init] autorelease];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame style:UITableViewStylePlain];
if(self)
{
self.delegate = self;
self.dataSource = self;
}
return self;
}
@end
ClickTvCell.m
#import "ClickTvCell.h"
@implementation ClickTvCell
- (void)uiInitialize
{
self.contentView.translatesAutoresizingMaskIntoConstraints = NO;
self.view = [[ClickTvCellContentView alloc] init];
self.view.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:self.view];
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0f constant:0.0f]];
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0f constant:0.0f]];
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0f constant:200.0f]];
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0f constant:44.0f]];
}
- (id)init
{
self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CLICK_TV_CELL"];
if(self)
{
[self uiInitialize];
}
return self;
}
@end
ClickTvCellContentView
#import "ClickTvCellContentView.h"
@implementation ClickTvCellContentView
- (void)ivClick:(id)sender
{
//此处监听不到
NSLog(@"========");
}
- (void)uiInitialize
{
self.iv = [[UIImageView alloc] init];
self.iv.translatesAutoresizingMaskIntoConstraints = NO;
self.iv.userInteractionEnabled = YES;
self.iv.image = [UIImage imageNamed:@"icon_my_score_normal"];
[self addSubview:self.iv];
UITapGestureRecognizer *gestureRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ivClick:)] autorelease];
[self.iv addGestureRecognizer:gestureRecognizer];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.iv attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0f constant:0.0f]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.iv attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0f constant:0.0f]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.iv attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeWidth multiplier:0.2f constant:0.0f]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.iv attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeHeight multiplier:1.0f constant:0.0f]];
}
- (id)init
{
self = [super init];
if(self)
{
[self uiInitialize];
}
return self;
}
@end