我在uiviewcontroller中的uiScrollview中有一个uibutton。当我单击按钮时,我希望能够调用uiviewcontroller中的方法。
我在我的按钮上有以下操作,它在我的uiscrollview中调用一个方法:
[categoryButton addTarget:self-action:@selector(categoryButtonWasClicked:)forControlEvents:UIControlEventTouchUpInside];
但这只是调用了我的uiscrollview中的一个方法(我仍将保留它)。然后如何在视图控制器中调用方法??
感谢您提供的任何帮助。
enter code here
尝试执行类似的操作
#import <UIKit/UIKit.h>
@protocol myUIScrollViewProtocol <NSObject>
-(void)buttonWasPressInScrollView:(id)sender;
@end
@interface MyUIScrollView : UIScrollView
@property (weak, nonatomic)id myDelegate;
@end
创建UIScrollView的子类并添加一个委托,然后将UIViewController指定为委托,并在其中实现"buttonWasPress.."方法。
然后从uiScrollView:中的CategoryButtonWasClicked方法
-(void)categoryButtonWasClicked{
if ([self.myDelegate respondsToSelector:@selector(buttonWasPressInScrollView:)]){
[self.myDelegate buttonWasPressInScrollView:self];
}
...
}
在您的视图Controller.h中添加以下
@interface MyViewController : UIViewController <myUIScrollViewProtocol>