菜鸟教程小白 发表于 2022-12-12 18:56:18

iphone - iOS Scrollview 检测滚动


                                            <p><p>我已经阅读了之前关于这个确切主题的所有帖子,但我仍然无法检测到用户何时在这个 iPad 应用上滚动...</p>

<p>我的.h:</p>

<pre><code>#import &lt;UIKit/UIKit.h&gt;

@interface MyApp_ViewController : UIViewController &lt;UIScrollViewDelegate&gt;
{

}
@property (weak, nonatomic) IBOutlet UIButton *otherButton;
@property (weak, nonatomic) IBOutlet UIScrollView *otherScrollView;
@property (weak, nonatomic) IBOutlet UITextView *txtViewHTML;

-(void)k_RootViewPrint:(NSString *) data;

-(void)ActionEventForButton: (id) sender;

@end
</code></pre>

<p>我的.m:</p>

<pre><code>-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{

    NSLog(@&#34;...&#34;);
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSLog(@&#34;2222&#34;);
}
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
{
    NSLog(@&#34;touches ended BS&#34;);
}
</code></pre>

<p>但它们都不起作用?我确信这很简单,但我已经做了我能想到的一切,但仍然一无所获。任何正确方向的指导将不胜感激!</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>如果它没有登录 <code>scrollViewDidScroll:</code>,那么 ScrollView 的委托(delegate)没有设置到 ViewController 。</p>

<p>您可以在调试器中检查这一点。应用启动后,暂停调试器并运行以下命令:</p>

<pre><code>po [[(id)UIApp keyWindow] recursiveDescription]
</code></pre>

<p>查看输出以找到您的 UIScrollView 的地址。会有一行写着 <code><UIScrollView: 0xc894d60 ...></code>。获取地址(在我的示例中为 <code>0xc894d60</code>)并在此调试器命令中使用它:</p>

<pre><code>po
</code></pre>

<p>如果它打印出类似 <code><MyApp_ViewController: 0x6a7f6c0></code> 的内容,则您的委托(delegate)设置正确。如果它打印“无法打印 NIL 对象的描述。”,您还没有设置 ScrollView 的委托(delegate)。如果它打印了其他内容,则说明您错误地设置了 ScrollView 的委托(delegate)。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - iOS Scrollview 检测滚动,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/8876451/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/8876451/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - iOS Scrollview 检测滚动