Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使UIView对象与ViewController对象通信_Ios_Iphone_Xcode - Fatal编程技术网

Ios 如何使UIView对象与ViewController对象通信

Ios 如何使UIView对象与ViewController对象通信,ios,iphone,xcode,Ios,Iphone,Xcode,我正在编写故事板中的iPhone应用程序。它里面有一个UIScrollView。其中有一个SliderView,这是我编写的一个自定义子类,它派生自UIView 在SliderView中,我正在执行此方法: // Inside SliderView.m - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // whenever someone touches inside of SliderView, th

我正在编写故事板中的iPhone应用程序。它里面有一个UIScrollView。其中有一个SliderView,这是我编写的一个自定义子类,它派生自UIView

在SliderView中,我正在执行此方法:

// Inside SliderView.m
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // whenever someone touches inside of SliderView, this method fires
}
这是我的问题。在我的故事板中,我想禁用UIScrollView的弹性垂直滚动

通常,这很容易。假设我已将UIScrollView连接为应用程序主ViewController中的IBOutlet,我可以将其粘贴到该文件中:

// Inside ViewController.m
- (void)viewDidLoad {
    [super viewDidLoad];
    self.scrollView.bounces = NO;
}
不幸的是,这并不是那么容易,因为我希望这种禁用只在触发ToucheSBegind时发生

因此,这里是我完全困惑的地方:如何让SliderView.m文件与ViewController.m文件通信

为此使用委托:

SliderView.h

ViewController.m

在ViewController中创建委托方法:

- (void) isScrollViewToBounce:(BOOL)isBounce {
    self.scrollView.bounces = isBounce;
}
也不要忘记删除委托

//--------------------------------


使用委派:如果SliderView是UIScrollView的子视图,您不能简单地添加UIScrollView*parentScrollView=self.superView;parentScrollView.bounces=否?在你的触摸屏内开始使用SliderView的方法?如krzysztof的回答所示,最好使用委托或弱存储属性。非常感谢。我靠蒸汽生活,但这看起来是合法的,我会尽快实施它,只要我赶上了睡眠!
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.sliderViewDelegate isScrollViewToBounce:NO];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.sliderViewDelegate isScrollViewToBounce:YES];
}
#import "SliderView.h"
@interface ViewController () <SliderViewDelegate>
@end
- (void)viewDidLoad {
   [super viewDidLoad];
   self.sliderView setSlideViewDelegate:self];
}
- (void) isScrollViewToBounce:(BOOL)isBounce {
    self.scrollView.bounces = isBounce;
}
#pragma mark Memory management methods
- (void)dealloc {
   // Release resources here.
   [self.scrollView setSliderViewDelegate:nil]
}