2014-09-30 4 views
1

내 TableView 앱에서 풀 새로 고침 기능을 구현하려고합니다. 그러나 응용 프로그램을 실행할 때 페이지를 새로 고치려면 바로 당길 수 있습니다. 나는 오류 처리가 신속의 일부라고 생각하지 않았기 때문에풀 다운시 UIRefreshControl이 충돌 함 - 캐치 예외 스위프트

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 

이 나를 혼란, 아직 예외가 포착되지 않은 나를 말하고있다 : 나는 콘솔에 다음과 같은 메시지가? 여기

내 새로 고침 코드가 같은 모습입니다 :

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() 
} 

답변

6

가에 콜론을 꺼내 "loadData :"

refreshControl!.addTarget(self, action: "loadData", forControlEvents: UIControlEvents.ValueChanged) 

또한 loadData 개인 방법으로 표시되지되어 있는지 확인하십시오.

+0

와우, 그게 효과가 있었어! 콜론이 필요하지 않은 이유를 알고 있습니까? 내 코드의 많은 다른 영역에서 콜론이 필요합니다. 예를 들어'logoutButton.addTarget (self, action : "logout :", forControlEvents : UIControlEvents.TouchUpInside)'콜론은 다른 곳에서 많이 사용하기 때문에 제거하지 못했을 것입니다. 고마워요! –

+1

메서드에 매개 변수가 있으면 콜론이 필요합니다. [documentation] (https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html#//apple_ref/doc/uid/TP40014216-CH4-XID_38)은 아닙니다. Swift에서 선택자와 너무 명확합니다. – lsw

+0

도움을 주셔서 감사합니다. 그냥 궁금해서, loadData 메소드를 호출하고 또한 매개 변수'refreshControl'를 보내고 싶다면, 어떻게 이것을 할 수 있을지 아십니까? 로드 데이터에서 'refreshControl! .endRefreshing()'을 호출해야하기 때문에 –