TouchesBegan not triggered in custom UIView on top of UITableView

Discussion in 'iOS Programming' started by drdos, Sep 30, 2011.

  1. drdos macrumors newbie

    Sep 28, 2011
    Hey Guys,

    So I am working on an app here, I have a tableview that display's some comments in a social network app.

    Apart of each cell inside the tableview I have built a custom cellview to display the data in the format I want.

    I then add a subview of a custom UIView that I am building dynamically to that custom cell of the following class:

    #import <UIKit/UIKit.h>
    #import <QuartzCore/QuartzCore.h>
    @interface actionStatsBar : UIViewController{
        UIView *actionView;
    @property(nonatomic, retain) UIView *actionView;
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
    #import "actionStatsBar.h"
    @implementation actionStatsBar
    @synthesize actionView;
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        return self;
    - (void)didReceiveMemoryWarning{
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
        // Release any cached data, images, etc that aren't in use.
    #pragma mark - View lifecycle
    // Implement loadView to create a view hierarchy programmatically, without using a nib.
    - (void)loadView{
        [super loadView];
        self.view.userInteractionEnabled = YES;
        self.view.bounds = CGRectMake(10, 60, 45.0, 20);
        self.view.clipsToBounds = YES;
        self.view.backgroundColor = [UIColor redColor];
        self.view.frame = CGRectMake(10, 60, 45.0, 20.0);
        self.view.layer.borderColor = [[UIColor blackColor] CGColor];
        self.view.layer.borderWidth = 1;
    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad
        [super viewDidLoad];
    - (void)viewDidUnload{
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    #pragma mark - Touches Delagtes
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
        NSLog(@"enter touch");
    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
        NSLog(@"enter finish touch");
    The problem is this:

    When the table is loaded with the data and displaying the custom cells, the custom view is there, but when I click/press on that view its being over written by the TouchesBegan delegate on the custom cellview I have built.

    Is there a way I can overwrite that - so when a user press/clicks on that custom view it will trigger the TouchesBegan event for that view and not the one inside the custom cell view?

  2. drdos thread starter macrumors newbie

    Sep 28, 2011
    Nevermind I figured it out.

    The isssue was inside my cellForRowAtIndexPath I was creating all the elements dynamically and when I was creating the custom UIView I was auto releasing it - so when I removed the autorelease it then worked.

Share This Page