UIRefreshControl在下拉时崩溃 - Uncaught Exception Swift

时间:2014-09-30 20:25:55

标签: swift uirefreshcontrol

我正在尝试在TableView应用程序中实现pull to refresh功能。但是,当我运行应用程序时,一旦我下拉刷新页面,它就会崩溃。我在控制台中收到以下消息:

2014-09-30 21:13:15.799 SimpleText[2031:601545] 17545849:_UIScreenEdgePanRecognizerEdgeSettings.edgeRegionSize=13.000000
2014-09-30 21:13:45.296 SimpleText[2031:601545] -[SimpleText.TimelineTableViewController loadData:]: unrecognized selector sent to instance 0x14d50d5e0
2014-09-30 21:13:45.300 SimpleText[2031:601545] *** Terminating app due to uncaught   exception 'NSInvalidArgumentException', reason: '-[SimpleText.TimelineTableViewControllerloadData:]: unrecognized selector sent to instance 0x14d50d5e0'
*** First throw call stack:
(0x189402084 0x198fb40e4 0x189409094 0x189405e48 0x18930b08c 0x18da6cb98 0x18da55dd8 0x18dba6834 0x100869158 0x100869118 0x100872320 0x100869118 0x10087cae4 0x10086af7c 0x10086cec8 0x1893b98dc 0x1893b7984 0x1892e5664 0x1923175a4 0x18da9e164 0x1001128b0 0x1001129bc 0x19962aa08)
libc++abi.dylib: terminating with uncaught exception of type NSException

这使我感到困惑,因为我没有认为错误处理是swift的一部分,但它告诉我异常未被捕获?

以下是我的刷新代码:

override func viewDidLoad() {
    super.viewDidLoad()

    refreshControl = UIRefreshControl()
    refreshControl!.attributedTitle = NSAttributedString(string: "Pull to refresh")
    refreshControl!.addTarget(self, action: "loadData:", forControlEvents: UIControlEvents.ValueChanged)
    self.tableView.addSubview(refreshControl!)

    //refresh posts when app is loaded
    self.loadData()
}

1 个答案:

答案 0 :(得分:6)

取出“loadData:”

中的冒号
    refreshControl!.addTarget(self, action: "loadData", forControlEvents: UIControlEvents.ValueChanged)

还要确保loa​​dData未标记为私有方法。