views:

238

answers:

1

I've got a UIButton on a table cell that is meant to pop up a UIActionSheet but the problem is the didSelectRowAtIndexPath captures that touch and its action takes precedence. Any clever way to override that action when the user touches the button and still have the default action when the user presses elsewhere in the cell?

Too bad there is no MoveToFront property.

+1  A: 

How you have add button on cell

i am putting one sample

in

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

...

    UIButton *btnDetail = [UIButton buttonWithType:UIButtonTypeRoundedRect] ;

    [btnDetail setFrame:CGRectMake(225.0f, 15.0f, 65.0f, 20.0f)] ;
    //btnDetail.backgroundColor = [UIColor grayColor];
    [btnDetail setTitle:@"Detail" forState:UIControlStateNormal];
    [btnDetail setTitleColor: [UIColor redColor] forState: UIControlStateNormal];
    [btnDetail.titleLabel setFont:[UIFont fontWithName:@"Verdana-Bold" size:12]];
    [btnDetail setBackgroundColor:[UIColor clearColor]];
    [btnDetail sizeThatFits:btnDetail.frame.size];
    [cell addSubview:btnDetail];
    [btnDetail addTarget:self 
               action:@selector(function1:)
     forControlEvents:UIControlEventTouchUpInside];
    [btnDetail setImage:[UIImage imageNamed:@"btn-detail.png"] forState:UIControlStateNormal];

if you have written

[btnDetail addTarget:self 
                   action:@selector(function1:)
         forControlEvents:UIControlEventTouchUpInside];

your button should able to capture touch event and function1 should be called... on it's touch event...

mihirpmehta
This is the method I am using. However, the didSelectRowAtIndexpath is getting the touch and not the UIControlEventTouchDownInside.The size of the button is 16x16 (the size of its background image) but I don't think making it larger is going to do anything.
Michael
try UIControlEventTouchUpInside then....
mihirpmehta
Nope. Anything else?Have you tried this yourself?
Michael
i have written above code on cellForRowAtIndexPath and button is perfectly receiving touch event.... for time being increase button size for making sure that you're clicking inside of button only..
mihirpmehta
I must apologize. You are indeed correct. Your method works fine. I had other errors preventing the implementation.Thanks for explaining and commenting.
Michael
you are welcome Michael... :)
mihirpmehta