UIButton does not work when it in UIScrollView

后端 未结 8 492
说谎
说谎 2020-12-01 10:38

My structure of views:

UITableView
  UITableViewCell
    UIScrollView
      CustomView
        UIButton

The problem is UIButton doesn\'t wo

8条回答
  •  佛祖请我去吃肉
    2020-12-01 11:39

    Came across the same scenario. UIScrollView in separate class and adding button through a custom view. 'NSNotificationCenter' helped me solving the issue. Sample code:

    -(void)tileTouchUpInside:(id)sender
    {    
        NSDictionary *dict=[NSDictionary dictionaryWithObject:@"index" forKey:@"index"];
    
        [[NSNotificationCenter defaultCenter]postNotificationName:@"Action" object:nil userInfo:dict];
    }
    

    In the class containing Scroll View:

    - (void)viewDidLoad
    {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doAction:) name:@"Action" object:nil];
    }
    -(void)doAction:(NSNotification *) notification
    {
        NSString* value =[notification.userInfo valueForKey:@"index"];
        // .......
    }
    

    Enable userInteraction for scroll view, custom view and button.

提交回复
热议问题