UIButton does not work when it in UIScrollView

后端 未结 8 461
说谎
说谎 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.

    0 讨论(0)
  • 2020-12-01 11:40

    I had same issue & same hierarchy of the views, With latest sdk , just use it :

    Setting delaysContentTouches to NO for UIButton in the same UITableViewCell.

    self.tableView.delaysContentTouches = NO
    
    0 讨论(0)
提交回复
热议问题