开发者

Enable AccessoryDetailButton even if cell is disabled

开发者 https://www.devze.com 2023-04-12 03:53 出处:网络
I want to have my UITableViewCell disabled but still be able to press the accessoryView button. I thought this would work:

I want to have my UITableViewCell disabled but still be able to press the accessoryView button.

I thought this would work:

cell.userInteractionEnabled = NO;
cell.accessoryView.userInteractionEnabled = YES;

But my UITableViewCellA开发者_运维问答ccessoryDetailDisclosureButton is still disabled.


accessoryView will get all his touchEvents from his superview, in this case your cell and wont react to your actions.

What might work is creating a touch event to that accesoryView on the viewController you make the tableView on and make it react to touches.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
{  
    UITouch *touch = [[event allTouches] anyObject];

    if ([touch view] == accessoryView) {
        //do something because you hit accessoryView
    }
}


If you disable a view, all its subviews will be disabled.


For this you have to set userInteractionEnabled =NO all subviews in cell expect in Disclosure and cell.


cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.userInteractionEnabled = YES;

Place this line in this method.

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


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   Leave this method blank. if u want to code in this delegate method so filter those row by code:  
 if(indexPath.row == row no in which u don't want click event)  
 {
    leave blank
 }
 else
 {
   code which u want .
 }
}

you get your click event for particular button in this method.

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;
0

精彩评论

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

关注公众号