开发者

UIButton to intercept UITableView's didSelectRowAtIndexPath method

开发者 https://www.devze.com 2022-12-27 00:08 出处:网络
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 overri

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 touche开发者_运维知识库s the button and still have the default action when the user presses elsewhere in the cell?

Too bad there is no MoveToFront property.


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消