2012-05-21 8 views
2

스토리 보드를 사용 중입니다 & 개 있습니다. 연락처 목록 (tableView)에서 "프로필보기"(ScrollView)로 전환하고 싶습니다.Storyboard & Segue - 좋은 결과를 얻고 있습니까?

세 가지 질문 :

  • 이것이 최선의 방법입니다 (& 아름다운 더 깨끗한)이 작업을 수행하려면? & 왜?
  • 내가 이렇게 할 때 : ProfileViewController * aProfileView = (ProfileViewController *) [segue destinationViewController]; 이 새로운 뷰를 인스턴스화합니까? (마치 2 개의 프로파일보기를 생성합니다).
  • 내가 청소해야합니까 ("프로필보기"어딘가 삭제 하시겠습니까?) 아니면 네비게이션 컨트롤러로 혼자하고 있습니까?

// 코드이 작업을 수행하는

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([[segue identifier] isEqualToString:@"showProfileSelected"]) 
    { 
     // Get the Selected raw 
     NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
     Profile *selectedProfile = [self.profilesTable objectAtIndex:indexPath.row]; 

     // Using segue --> Send the current selected profile to "ProfileView" 
     ProfileViewController *aProfileView = (ProfileViewController *)[segue destinationViewController]; 
     aProfileView.currentProfile = selectedProfile; 
    } 
} 

// 다른 방법 :

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([[segue identifier] isEqualToString:@"showProfileSelected"]) 
    { 
     // Get the Selected raw 
     NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
     Profile *selectedProfile = [self.profilesTable objectAtIndex:indexPath.row]; 

     // Using segue --> Send the current selected profile to "ProfileView" 
     [segue.destinationViewController setCurrentProfile:selectedProfile]; 
    } 
} 

답변

1

첫 번째 예는 괜찮습니다. 아무 것도 만들지 않고 목적지 컨트롤러에 대한 참조를 얻는 것뿐입니다. 이와 같은 변수를 설정하면 반복해서 캐스트하지 않고도 대상보기 컨트롤러에서 여러 속성을 설정할 수 있습니다. 그래서

는, 특정 질문에 대답하기 :

  • 네, 가장 좋은 방법입니다. destination보기 컨트롤러의 일반 클래스로 인해 prepareForSegue "beautiful"를 얻는 것은 어렵습니다.
  • 아니요, 아무 것도 만들지 않습니다.
  • 아니요, 정리할 것이 없습니다.
+0

답장을 보내 주셔서 감사합니다. 이게 필요한거야? (ProfileViewController *) 또한 그것없이 작동하기 때문에. – Slake

+0

그래도 컴파일러 경고가 표시됩니다. 거기서 뭐하는거야 캐스트, 그리고 그것은 컴파일러가 어떤 클래스 (예 : ProfileViewController, UIViewController 아닌) 알고 보자 – jrturton

+0

아니요, 컴파일러 경고가 점점 아니에요 - 잘 모르겠습니다 캐스트입니다. 다시 한번 감사드립니다. – Slake

관련 문제