2014-12-02 5 views
2

테이블 뷰 셀을 탭하면 내 iOS 앱이 빠르게 중단됩니다. 이것은 모두 프로그래밍 방식으로 수행되었습니다. (수동 segue 제외) 내가 셀을 탭하면 Dynamic Cast Call Failed가 발생합니다.다이내믹 캐스트 호출 실패

CoreData, Segue 또는 내 tableview와 관련이 있습니까? 오류는 내가 segue를 작동 시켰을 때만 나타났습니다. 테이블과 CoreData에 대한 동일한 코드가 Storyboard에서 생성 된 테이블과 뷰와 함께 사용되기 전에 (didSelectRowAtIndex 제외) 그런 다음 모든 것이 효과가있었습니다. 불행히도 스토리 보드를 통해 앱을 실행하는 것은 앱의 나머지 옵션에 대한 옵션이 아닙니다.

정말 여기에서 길을 잃었습니다. 필요한 경우 더 많은 코드를 게시 할 수 있습니다.

고맙습니다.

이것은 오류가 발생했습니다.

libswiftCore.dylib`swift_dynamicCastClassUnconditional: 
0x1042679e0: pushq %rbp 
0x1042679e1: movq %rsp, %rbp 
0x1042679e4: testq %rdi, %rdi 
0x1042679e7: je  0x104267a1e    ; swift_dynamicCastClassUnconditional + 62 
0x1042679e9: movabsq $-0x7fffffffffffffff, %rax 
0x1042679f3: testq %rax, %rdi 
0x1042679f6: jne 0x104267a1e    ; swift_dynamicCastClassUnconditional + 62 
0x1042679f8: leaq 0xb5109(%rip), %rax 
0x1042679ff: movq (%rax), %rax 
0x104267a02: andq (%rdi), %rax 
0x104267a05: nopw %cs:(%rax,%rax) 
0x104267a10: cmpq %rsi, %rax 
0x104267a13: je  0x104267a2d    ; swift_dynamicCastClassUnconditional + 77 
0x104267a15: movq 0x8(%rax), %rax 
0x104267a19: testq %rax, %rax 
0x104267a1c: jne 0x104267a10    ; swift_dynamicCastClassUnconditional + 48 
0x104267a1e: leaq 0x36b3d(%rip), %rax  ; "Swift dynamic cast failed" 
0x104267a25: movq %rax, 0xb4a2c(%rip)  ; gCRAnnotations + 8 
0x104267a2c: int3 
0x104267a2d: movq %rdi, %rax 
0x104267a30: popq %rbp 
0x104267a31: retq 
0x104267a32: nopw %cs:(%rax,%rax) 

이 내 관련 코드 (내가 생각하는) 수정 코드


func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
     self.performSegueWithIdentifier("update", sender: self) 
     println("You selected a cell") 

    } 

편집

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
     if segue.identifier? == "update" { 
      var selectedItem: NSManagedObject = myTodos[self.todoTableView.indexPathForSelectedRow()!.row] as NSManagedObject 

      let IVC: TodoViewController = segue.destinationViewController as TodoViewController 

      IVC.todoItem = selectedItem.valueForKey("todoItem") as String 
      IVC.todoTime = selectedItem.valueForKey("todoTime") as NSDate 

      IVC.existingTodo = selectedItem 
     } 
    } 
입니다 : 문제가를 전달하는 데 노력에 의해 발생 된 네비게이션 컨트롤러를 통한 세그.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
     if segue.identifier? == "update" { 
      var selectedItem: NSManagedObject = myTodos[self.todoTableView.indexPathForSelectedRow()!.row] as NSManagedObject 

      let navVC = segue.destinationViewController as UINavigationController 

      //let tableVC = navVC.viewControllers.first as YourTableViewControllerClass 
      let IVC: TodoViewController = navVC.viewControllers.first as TodoViewController 


      IVC.todoItem = selectedItem.valueForKey("todoItem") as String 
      IVC.todoTime = selectedItem.valueForKey("todoTime") as NSDate 

      IVC.existingTodo = selectedItem 
     } 
    } 

업데이트 : 코드에서 네 다운 캐스트를 참조

let IVC: TodoViewController = (segue.destinationViewController as UINavigationController).viewControllers.first as TodoViewController 

또는

let IVC: TodoViewController = segue.destinationViewController.topViewController as TodoViewController 

답변

2

:

var selectedItem: NSManagedObject = myTodos[self.todoTableView.indexPathForSelectedRow()!.row] as NSManagedObject 
let IVC: TodoViewController = segue.destinationViewController as TodoViewController 
IVC.todoItem = selectedItem.valueForKey("todoItem") as String 
IVC.todoTime = selectedItem.valueForKey("todoTime") as NSDate 

내 생각 엔 오류가 중 하나라는 것이다 마지막 2 행 -하지만 브레스트를 넣으라고 제안합니다. 첫 번째 줄에서 점을 찍어 코드를 단계별로 실행하면 실제로 오류를 생성하는 행을 찾을 수 있습니다.

+0

그래서 중단 점은 다음과 같습니다.) Cool! –

+0

그것은 첫 번째 '하자 IVC : TodoViewController = segue.destinationViewController로 TodoViewController' –

+0

[이것은 실제 문제를 설명했다] (http : // stackoverflow.co.kr/questions/24327267/swift-dynamic-cast-failed-uipageviewcontroller) 나는 길에 내비게이션 컨트롤러가 있습니다. 어느 쪽이든 다운 캐스팅 오류가 발생하거나 내 탐색 막대가 없습니다. 하지만 지금은 작동합니다 :) –

1

tableview 컨트롤러가 UINavigationController에 내장 된 경우 segue.destinationViewController는 UINavigationController 인스턴스이며 TodoViewController 인스턴스는 아닙니다.

당신은 아마 당신의 탐색 컨트롤러를 유지하고이 줄을 교체 한 수

이와

let IVC: TodoViewController = segue.destinationViewController as TodoViewController

:

let IVC: TodoViewController = segue.destinationViewController.topViewController as TodoViewController` 

은 UINavigationController의 .topViewController 속성이 탐색 스택의 상단에 의미를 , 귀하의 TodoViewController이어야합니다.

+0

수정 된 코드로 마지막 편집을 보면, 비슷한 것을 보여줍니다. –

+0

네, 비슷한 것을 보여 주며, 당신이 그것을 해결해 주어 기쁘다. 그리고 나의 대답이 같은 이슈를 가진 다른 사람들에게 가치를 더하기를 바랍니다. – tonethar

+0

내 코드를보고 (내가이 모든 것으로 시작했을 때부터) 여러분과 그것을 비교하면 코드 조각이 여러분의 것과 똑같이 보이도록 최적화 될 수 있음을 깨닫게됩니다. 이제는 모든 일을 할 수 있지만 여전히 생각하지 않고 코드 조각을 사용합니다 :) –