【问题标题】:How to add UIRefreshControl如何添加 UIRefreshControl
【发布时间】:2014-08-06 07:11:55
【问题描述】:

我想将 UIRefreshControl 添加到我的应用程序中,该应用程序在下拉表时从数据库中获取记录,我已经完成了以下代码,但它给了我类似的错误

2014-08-06 12:31:56.263 QuizUsindDB[1183:60b] -[ScoreViewController readScoreFromDatabase]: unrecognized selector sent to instance 0x8d3d8e0
2014-08-06 12:31:56.266 QuizUsindDB[1183:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ScoreViewController readScoreFromDatabase]: unrecognized selector sent to instance 0x8d3d8e0'
*** First throw call stack:
(
    0   CoreFoundation                      0x018f81e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x016778e5 objc_exception_throw + 44
    2   CoreFoundation                      0x01995243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x018e850b ___forwarding___ + 1019
    4   CoreFoundation                      0x018e80ee _CF_forwarding_prep_0 + 14
    5   libobjc.A.dylib                     0x0168982b -[NSObject performSelector:withObject:] + 70
    6   UIKit                               0x003393b9 -[UIApplication sendAction:to:from:forEvent:] + 108
    7   UIKit                               0x00339345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    8   UIKit                               0x0043abd1 -[UIControl sendAction:to:forEvent:] + 66
    9   UIKit                               0x0043afc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
    10  UIKit                               0x0043ac06 -[UIControl sendActionsForControlEvents:] + 48
    11  UIKit                               0x00a227e9 -[UIRefreshControl _setRefreshControlState:notify:] + 404
    12  UIKit                               0x00a22650 -[UIRefreshControl setRefreshControlState:] + 48
    21  CoreFoundation                      0x0195d43e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
    22  CoreFoundation                      0x0189e5cb __CFRunLoopRun + 1963
    23  CoreFoundation                      0x0189d9d3 CFRunLoopRunSpecific + 467
    24  CoreFoundation                      0x0189d7eb CFRunLoopRunInMode + 123
    25  GraphicsServices                    0x038ec5ee GSEventRunModal + 192
    26  GraphicsServices                    0x038ec42b GSEventRun + 104
    27  UIKit                               0x00337f9b UIApplicationMain + 1225
    28  QuizUsindDB                         0x0001038d main + 141
    29  libdyld.dylib                       0x01e41701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

上面给出了 UIRefreshControl 的代码:

-(void)pullToRefresh
{
    self.refreshControl = [[UIRefreshControl alloc] init];
    self.refreshControl.tintColor = [UIColor blackColor];
    [self.refreshControl addTarget:self action:@selector(readScoreFromDatabase)
                  forControlEvents:UIControlEventValueChanged];
    [self.myTable addSubview:self.refreshControl];
    [self.refreshControl endRefreshing];

}

我在 viewDidLoad 中调用了 [self pullToRefresh]。

我有上面的代码来初始化和调用选择器来刷新表格。 我无法识别错误,谁能指出我的错误。

【问题讨论】:

  • 日志说,readScoreFromDatabase 方法不存在,您能否仔细检查self 中的方法是否具有相同的拼写,并且方法声明中没有参数变量。

标签: ios uitableview uirefreshcontrol


【解决方案1】:

改变这一行:

[self.refreshControl endRefreshing];

到这里:

[self.refreshControl beginRefreshing];

endRefreshing 方法应该在表视图完成重新加载数据后调用。

此外,崩溃日志表明您的 -[ScoreViewController readScoreFromDatabase]: 函数不存在。

【讨论】:

  • 它给了我这样的错误,“UIRefreshControl”没有可见的@interface 声明选择器“startRefreshing”
  • 你调用的方法也有问题。
  • ScoreViewController 正在调用方法readScoreFromDatabase。确保该函数存在。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-19
  • 1970-01-01
  • 2015-08-08
  • 1970-01-01
  • 2013-10-29
  • 1970-01-01
相关资源
最近更新 更多