1
votes

I have a uibutton inside a uiScrollview inside a uiviewcontroller. When I click the button I want to be able to call a method in the uiviewcontroller.

I have the following action on my button that calls a method within my uiscrollview:

[categoryButton addTarget:self action:@selector(categoryButtonWasClicked:) forControlEvents:UIControlEventTouchUpInside];

But this just calls a method within my uiscrollview (which I will still keep). How do I then call a method in the viewcontroller??

Thank you for any help you can provide.

1

1 Answers

1
votes

enter code hereTry doing something like this

#import <UIKit/UIKit.h>

@protocol myUIScrollViewProtocol <NSObject>

    -(void)buttonWasPressInScrollView:(id)sender;

@end

@interface MyUIScrollView : UIScrollView

@property (weak, nonatomic)id myDelegate;

@end

Create a subclass of UIScrollView and add a delegate then assign your UIViewController as the delegate and implement the "buttonWasPress.." method in it.

Then from the categroryButtonWasClicked method in your uiScrollView:

    -(void)categoryButtonWasClicked{
    if ([self.myDelegate respondsToSelector:@selector(buttonWasPressInScrollView:)]){
        [self.myDelegate buttonWasPressInScrollView:self];
    }
...
}

in your viewController's .h add the following

@interface MyViewController : UIViewController <myUIScrollViewProtocol>