diff --git a/example/UIBubbleTableViewExample/ViewController.m b/example/UIBubbleTableViewExample/ViewController.m index 5516175..0bf29d8 100644 --- a/example/UIBubbleTableViewExample/ViewController.m +++ b/example/UIBubbleTableViewExample/ViewController.m @@ -129,7 +129,9 @@ - (void)keyboardWillBeHidden:(NSNotification*)aNotification } #pragma mark - Actions - +- (void)didSelectNSBubbleDataCell:(NSBubbleData *)dataCell{ + NSLog(@"Image Option"); +} - (IBAction)sayPressed:(id)sender { bubbleTable.typingBubble = NSBubbleTypingTypeNobody; diff --git a/src/NSBubbleData.m b/src/NSBubbleData.m index 5a39821..80e9ab2 100644 --- a/src/NSBubbleData.m +++ b/src/NSBubbleData.m @@ -94,18 +94,18 @@ - (id)initWithImage:(UIImage *)image date:(NSDate *)date type:(NSBubbleType)type size.width = 220; } - UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)]; - imageView.image = image; - imageView.layer.cornerRadius = 5.0; - imageView.layer.masksToBounds = YES; + UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom]; + button.frame = CGRectMake(0, 0, size.width, size.height); + button.tag = 1; + [button setBackgroundImage:image forState:UIControlStateNormal]; #if !__has_feature(objc_arc) - [imageView autorelease]; + [button autorelease]; #endif UIEdgeInsets insets = (type == BubbleTypeMine ? imageInsetsMine : imageInsetsSomeone); - return [self initWithView:imageView date:date type:type insets:insets]; + return [self initWithView:button date:date type:type insets:insets]; } #pragma mark - Custom view bubble diff --git a/src/UIBubbleTableView.m b/src/UIBubbleTableView.m index 29e4ddb..bb2aec6 100644 --- a/src/UIBubbleTableView.m +++ b/src/UIBubbleTableView.m @@ -227,9 +227,25 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.data = data; cell.showAvatar = self.showAvatars; + UIButton *button = (UIButton*)[data.view viewWithTag:1]; + [button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside]; + return cell; } - +- (void) checkButtonTapped:(id)sender event:(id)event { + NSSet *touches = [event allTouches]; + UITouch *touch = [touches anyObject]; + CGPoint currentTouchPosition = [touch locationInView:self]; + NSIndexPath *indexPath = [self indexPathForRowAtPoint: currentTouchPosition]; + // NSLog(@"indexPath=%@",indexPath); + if (indexPath.row != 0) + { + NSBubbleData *data = [[self.bubbleSection objectAtIndex:indexPath.section] objectAtIndex:indexPath.row - 1]; + [self.bubbleDataSource didSelectNSBubbleDataCell:data]; + } + + +} #pragma mark - Public interface - (void) scrollBubbleViewToBottomAnimated:(BOOL)animated diff --git a/src/UIBubbleTableViewDataSource.h b/src/UIBubbleTableViewDataSource.h index 01194e7..526e000 100644 --- a/src/UIBubbleTableViewDataSource.h +++ b/src/UIBubbleTableViewDataSource.h @@ -20,5 +20,5 @@ - (NSInteger)rowsForBubbleTable:(UIBubbleTableView *)tableView; - (NSBubbleData *)bubbleTableView:(UIBubbleTableView *)tableView dataForRow:(NSInteger)row; - +- (void)didSelectNSBubbleDataCell:(NSBubbleData *)dataCell; @end