简体   繁体   English

如何在我的UIViewController中调用UIView方法?

[英]How to call a UIView method in my UIViewController?

I have a method to create a rectangle in my custom uiview and I want to call it in my UIViewController.I am trying to use UITapGestureRecognizer in my UIViewController and check if a point in the rectangle is called. 我有一个在自定义uiview中创建矩形的方法,我想在UIViewController中调用它。我试图在UIViewController中使用UITapGestureRecognizer并检查是否调用了矩形中的一个点。

rectangle in my custom uiview ( myView.m ) 我的自定义uiview中的矩形(myView.m)

- (CGRect) myRect
{
    return CGRectMake(10, 10, self.bounds.size.height - 20, self.bounds.size.height - 20);
}

UITapGestureRecognizer method in my MyViewController.m MyViewController.m中的UITapGestureRecognizer方法

- (void)viewDidLoad
{
    [super viewDidLoad];
[self.PlayDraw setNeedsDisplay];

}


- (IBAction)handleTap:(UITapGestureRecognizer *)sender {
    CGPoint point = [sender locationInView:self.view];

    if(CGRectContainsPoint([self.PlayDraw myRect],point)) {
        NSLog(@"touched");

    }

and I get an error for [self.PlayDraw myRect] that says 我收到[self.PlayDraw myRect]的错误消息,内容为

No visible @interface for 'MyViewController' declares the selector 'myRect' 'MyViewController'没有可见的@interface声明选择器'myRect'

and here is my MyViewController.h 这是我的MyViewController.h

@interface MyViewController : UIViewController
{

}
- (IBAction)handleTap:(UITapGestureRecognizer *)sender;
@property (strong, nonatomic) IBOutlet myView *PlayDraw;
@end

In your myView.h file add: 在您的myView.h文件中添加:

- (CGRect) myRect;

You have to expose this method to other classes. 您必须将此方法公开给其他类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从自定义UIView调用UIViewController内部的方法/动作? - How to call a method/an action inside UIViewController from custom UIView? 如何从UIView子类调用UIViewController方法 - How can I call a UIViewController method from an UIView subclass 如何在自定义uiview中调用UIViewController属性? - How to call a UIViewController property in custom uiview? 如何从UIView子类调用UIViewController? - How to call a UIViewController from a UIView SubClass? UIViewController和UIView中的Touches方法 - Touches method in UIViewController and UIView 如何从单独的非UIViewController类调用ViewController的方法 - How to call method of my ViewController from separate non UIViewController Class 如何从UIViewcontroller类调用类别方法? - How can I call a category method from my UIViewcontroller class? 覆盖UIView子类中的drawRect方法,并将其调用到另一个UIViewcontroller中 - Overriding drawRect method in a UIView subclass & call it into another UIViewcontroller 是否有任何用于UIView的viewDidAppear方法(不是UIViewController)? - Is there any viewDidAppear method for UIView (not UIViewController)? 如何从UIViewController类到Custom UIView类调用方法 - How to invoke a method from UIViewController class to Custom UIView class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM