2015-01-04 5 views
0

나는 사용하고있는 푸시 성 segue가 있습니다. 그런 다음 데이터 푸시에 사용중인 segue를 준비합니다. 데이터를 푸는 데 긴장을 풀 필요가 있지만이를 결합하는 데 문제가 있습니다. 다음은 언 와인드 SEGUE 코드 -unwind segues를 사용하여 데이터 푸시

- (IBAction)unwindFromDetailViewController:(UIStoryboardSegue *)segue { 
    // ViewController *detailViewController = [segue sourceViewController]; 
    NSLog(@"%@", segue.identifier); 
} 

그리고 여기가 SEGUE 코드에 대한 준비이다 -

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if ([segue.identifier isEqualToString:@"showRecipeDetail"]) { 
     NSIndexPath *indexPath = nil; 
     Recipe *recipe = nil; 
     if (self.searchDisplayController.active) { 
      indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow]; 
      recipe = [searchResults objectAtIndex:indexPath.row]; 
     } else { 
      indexPath = [self.tableView indexPathForSelectedRow]; 
      recipe = [recipes objectAtIndex:indexPath.row]; 
     } 

     PersonDetailTVC *destViewController = segue.destinationViewController; 
     destViewController.recipe = recipe; 

     [self dismissViewControllerAnimated:YES completion:nil]; 
    } 
} 

을 그리고 여기 내가있는이 SEGUE를 풀기하지만, 데이터를 밀어되지 시도 것입니다.

- (IBAction)unwindFromDetailViewController:(UIStoryboardSegue *)segue { 
    if ([segue.identifier isEqualToString:@"CustomTableCell"]) { 
     NSIndexPath *indexPath = nil; 
     Recipe *recipe = nil; 
     if (self.searchDisplayController.active) { 
      indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow]; 
      recipe = [searchResults objectAtIndex:indexPath.row]; 
     } else { 
      indexPath = [self.tableView indexPathForSelectedRow]; 
      recipe = [recipes objectAtIndex:indexPath.row]; 
     }  

     PersonDetailTVC *destViewController = segue.destinationViewController; 
     destViewController.recipe = recipe; 

     [self dismissViewControllerAnimated:YES completion:nil]; 
    } 
} 
+1

같은 질문에 대한 재 게시는 계속하고 있지만 이미 정확한 주제에 대한 답변이 많은이 게시물로 이동했습니다. "나는 단편을 풀 때 데이터를 반환 할 수 있습니까?" http://stackoverflow.com/q/13038622/2274694. 나는 당신이 그것을 조사 할 것을 제안한다. –

+0

질문에 답변이 없으면 같은 질문 3 번을 다시 게시하는 대신 명확하게하기 위해 작업하는 것이 좋습니다. –

+1

* unwind segue *에 대한 식별자를 구체적으로 설정 했습니까? 나는 당신이 * segue * 식별자를 사용하고 있고 prepareForSegue에서'if ([segue.identifier isEqualToString : @ "showRecipeDetail"])'이 false를 반환하고 블록이 전혀 실행되지 않는다고 생각한다. (이 줄 :'[self dismissViewControllerAnimated : YES completion : nil];'은 불필요합니다.) –

답변

1

귀하의 질문의 오히려 불완전 그래서 나는 단지

는 첫째,이 방법은 당신이에 을 반환하고 뷰 컨트롤러에 있어야합니다 ... 가정을 기반으로 응답 할 수 있습니다.

- (IBAction)unwindFromDetailViewController:(UIStoryboardSegue *)segue { 

} 

둘째, 그 두번째 뷰 컨트롤러에서 데이터를 전달하기 위해 prepareForSegue: 방법 (제 뷰 컨트롤러에 속함) 아닌 unwindFromDetailViewController: 방법을 사용한다. 나는 당신이 당신의 if ([segue.identifier isEqualToString:@"showRecipeDetail"]) 진술서에 당신의 forward segue의 식별자를 사용하고 unwind segue의 식별자를 사용하고 있지 않으므로 false를 리턴하고 따라서 prepareForSegue: 메소드의 전체 블록이 전혀 실행되지 않는다고 믿습니다.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 

    NSIndexPath *indexPath = nil; 
    Recipe *recipe = nil; 
    if (self.searchDisplayController.active) { 
     indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow]; 
     recipe = [searchResults objectAtIndex:indexPath.row]; 
    } else { 
     indexPath = [self.tableView indexPathForSelectedRow]; 
     recipe = [recipes objectAtIndex:indexPath.row]; 
    } 

    PersonDetailTVC *destViewController = segue.destinationViewController; 
    destViewController.recipe = recipe; 
} 

경우 : 그래서 데이터가 예상, 전으로 전달되는 경우 만보고 지금은 조건을 제거해보십시오. (이 줄은 언 와인드이 모든 것이 올바르게 엮은 자동으로 한 발생하기 때문에 [self dismissViewControllerAnimated:YES completion:nil]; 불필요한 완료) segue의 식별자에 대한 검사를 지정하는 조건을 다시 추가하려면 unwind segue에 대한 식별자를 구체적으로 설정해야합니다.

+0

당신이 제안한 prepareforsegue를 시도했지만 아직 정보를 전달하지 못하고 있습니다. 이해가 안되는지 모르겠습니다. 네가하는 말이나 뭐야. 그러나 그것은 여전히 ​​아무것도하지 않습니다. –

+0

내가 말했듯이, 질문이 불완전하다. 예를 들면, unwindFromDetailViewController :는 unwind하고있는 뷰 컨트롤러에 있는가? 너의 segue가 제대로 설치 되었는가? 'prepareForeSegue'가 호출되고 있습니까? 확인을 위해 중단 점이나 nslog를 넣었습니까? 그리고 데이터가 전달되지 않았다고 어떻게 결정합니까? 방법에 대한 자세한 정보를 제공 할 필요가 있습니다 ... –

+0

보기 컨트롤러에서 긴장을 풀고보기 컨트롤러에서 prepareforsegue를 풀고 있습니다. 푸시 segue없이 정보를 전달하는 방법은 무엇입니까? 두 번째는 긴장을 푸는 첫 번째? \ –

관련 문제