UITableViewCell 上的ImageView响应

来源:互联网 发布:域名交易平台有哪些 编辑:程序博客网 时间:2024/06/05 16:20

TapView继承于UIImageView,接收touch事件。


- (void)viewDidLoad

{

    [super viewDidLoad];

    self.tableView = [[[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)] autorelease];

    self.tableView.delegate = self;

    self.tableView.dataSource = self;

    [self.view addSubview:self.tableView];

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return 10;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    NSString *cellId = @"cell";

    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];

    if(cell == nil)

    {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];

        TapView *iv = [[TapView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];

        iv.userInteractionEnabled = YES;

        iv.backgroundColor = [UIColor blueColor];

        [cell addSubview:iv];

        [cell autorelease];

    }

    return cell;

}