我有一个 UIView 添加到我的 rootViewController,UIView 检测到触摸并使用它们的坐标返回一个特定的整数,但是我不知道如何将这个整数返回到我的 rootViewController。我在某处读到 MVC 说 UIView 不应该知道 viewcontroller,这是真的吗?如果那么我怎么能做到这一点?谢谢!
最佳答案
我建议您定义一个在它们之间传递整数的协议(protocol)。让您的 View Controller 实现协议(protocol)并将其分配给 View 。然后,从 View 中,使用所需的值触发协议(protocol)方法。
协议(protocol)示例:
@protocol YourProtocol
-(void)handleCaptureInteger:(NSInteger)value;
@end
View Controller (.h) 示例:
@interface YourViewControler : UIViewController<YourProtocol>
...
@end
View Controller (.m) 示例:
@implementation YourViewController
- (void)viewDidLoad
{
[yourView setDelegate:self];
}
@end
查看示例:
@interface YourView : UIView
@property (nonatomic, assign) NSObect<YoutProtocol> *delegate;
@end
关于iphone - 将 Int 从 subview 返回到 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7408822/