2016-09-20 5 views
2

스위프트 3으로 업데이트 한 후 나는 다음과 같은 코드에서 오류가 발생합니다 :스위프트 3 UITableViewDataSource 선택기

extension MyViewController: UITableViewDataSource { 
    //... 

    func tableView(_ tableView: UITableView, 
        heightForRowAt indexPath: IndexPath) -> CGFloat { 
     return someValue 
    } 
} 

목표 - C 방법 '있는 tableView : heightForRowAt'방법 '있는 tableView (_에서 제공 : heightForRowAt :) '(있는 tableView를 : heightForRowAtIndexPath를') 요구 사항의 셀렉터에 일치하지 않습니다 '

그것은

012으로 고정 할 수 있습니다

누구나 Swift의 새 버전에서 변경되는 서명의 동기 부여를 설명 할 수 있습니까? 그것에 관한 정보가 없습니다 migration guide.

+1

참조 http://stackoverflow.com/questions/39416385/swift-3-objc-optional-protocol-method-not-called-in-subclass –

답변

2

Swift 3.0 라이브러리는 가독성을 위해 많은 메소드의 서명이 변경되었습니다 (API Design Guidelines 참조).

예를 들어 당신이 엑스 코드의 코드 완성 제안 목록에서 해당 표현으로 인용 한 방법의 현재의 서명을 비교해 대조적으로

// implementation: 
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {...} 

// code completion: 
tableView(tableView: UITableView, heightForRowAt: IndexPath) 

중복 정보를 표시하는 데 사용 이전의 구현 :

// implementation: 
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {...} 

// code completion: 
tableView(tableView: UITableView, heightForRowAtIndexPath: NSIndexPath) 
               --------- ----------- 

또한 함수 나 메소드를 구현하려면 첫 번째 인수에도 밑줄 (_)을 설정해야합니다.이 경우 밑줄 함수/메소드를 호출 할 때 인수 레이블을 지정하십시오 (참조 : https://stackoverflow.com/a/38192263/6793476 참조).

분명히 라이브러리의 일부 선택기가 아직 업데이트되지 않았으므로 적절한 ("이전") 선택기 이름을 제공해야합니다 (https://stackoverflow.com/a/39416386/6793476 참조 및 선택 자에 대한 자세한 내용은 https://stackoverflow.com/a/24007718/6793476).

도움이 되었기를 바랍니다.