【问题标题】:UIView not firing methods in the UIScrollView delegateUIView 未触发 UIScrollView 委托中的方法
【发布时间】:2011-06-18 06:02:17
【问题描述】:

我想知道是否有人可以解释一下为什么 UIScrollView 委托中的任何方法都没有被触发。

设置场景。我有一个 UIViewController 被推送到堆栈上。在这个视图中,我制作了 5 个自定义选项卡。在每次点击时,我都有一个功能,其中包含来自 UIViewController/xib 组合的 5 个视图(每个选项卡一个)。

ExercisePhotoView *exercisePhotoView = [[ExercisePhotoView alloc] initWithNibName:@"ExercisePhotoView" bundle:nil];
exercisePhotoView.exercise = self.exercise;
[self.photoView addSubview:exercisePhotoView.view];
[exercisePhotoView release];

在其中一个加载的视图中,我有一个滚动视图,其中包含一些图像(上面的代码块是上述视图)。 self.exercise 是一个 NSManagedObject。图像被很好地加载到滚动视图控制器中并且分页工作。然而,任何 ScrollView 的委托方法都不起作用,例如

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)theScrollView

我已经在我的头文件中包含了对委托的引用。

@interface ExercisePhotoView : UIViewController <UIScrollViewDelegate> {
    IBOutlet UIScrollView   *scrollView;
    IBOutlet UIPageControl  *pageControl;

    Exercise                *exercise;
    NSMutableArray          *exerciseImageList; 
}

我是否遗漏了什么或做错了什么。我无法在 ExercisePhotoView 类上触发任何委托方法。

提前谢谢你。

【问题讨论】:

    标签: iphone ios uiviewcontroller uiscrollview uiscrollviewdelegate


    【解决方案1】:

    您必须告诉卷轴它的委托人是谁,这样我才能知道将委托通知发送给谁。

    【讨论】:

      【解决方案2】:

      记得在你的标题中添加@property (nonatomic, retain) UIScrollView *scrollView;,在你的.m

      中添加@synthesize scrollView;

      【讨论】:

        【解决方案3】:

        虽然您已经声明,ExercisePhotoView 实现了 UIScrollViewDelegate 协议,但您还没有通知它作为委托的 UIScrollView 的任何实例

        因此,在ExercisePhotoView 的viewDidLoad(或其他适当的方法)中,您需要声明ExercisePhotoView 是特定scrollView 实例的委托:

        scrollView.delegate = self;
        

        【讨论】:

          【解决方案4】:

          您必须将self.scrollView.delegate 设置为应该充当scrollView 委托的对象。

          【讨论】:

          • 嗨菲利普,感谢您的意见,我添加了以下“self.scrollView.delegate = self;”到我的运动照片视图。该应用程序因 EXC_BAD_ACCESS 而崩溃,在启用 NSZombies 后,我现在收到以下错误并知道现在发生了什么。 *** -[ExercisePhotoView respondsToSelector:]:消息发送到已释放实例 0x5ce90a0
          • 只是为了澄清崩溃仅在尝试调用 scrollView 委托方法时发生。
          • 感谢大家的帮助。我终于找到了问题所在。似乎当我将视图添加到主视图和 [exercisePhotoView release] 行时;在我添加了 ExercisePhotoView 之后,这就是我所有邪恶的途径。
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-05-15
          • 2018-11-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多