I have custom UIViewController which looks like this.
@implementation UIViewControllerCustom
- (id)init
{
self = [super init];
if (self) {
NSLog(@"init");
}
return self;
}
-(void)viewDidLoad
{
[super viewDidLoad];
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton setFrame:CGRectMake(290, 10, 16, 16)];
[infoButton addTarget:self action:@selector(showInfo) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:infoButton];
}
-(void)showInfo
{
About *about = [[About alloc]init];
NSLog(@"touched");
[about setModalTransitionStyle:UIModalPresentationFullScreen];
[self presentModalViewController:about animated:YES];
}
@end
Any view controller in my app inherits this controller. When info button is touched the modal window is present. The problem is that one of my view controllers use UIScrollView. In this controller info button is visible and it reacts on touches. The problem is that when I touch the button showInfo method of UIViewControllerCustom is not called. I have no such a problem in the other controller.
What can be wrong here ?
Because the UIScrollView handles the message being sent. In your case the touch on the button will be handled by the UIScrollView.
I would suggest you to subclass the UIScrollView and implement:
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)viewto determine if the UIScrollView should handle the event or not.The implementation could be something along the lines of: