2012-01-06 2 views
-2

두 개의 UITableViewController (UINavigationController에 연결됨)가 있습니다. 첫 번째 컨트롤러에서 UITableViewCell을 클릭하면 세그 (segue)가 생성되어 두 번째 컨트롤러가 표시됩니다. 내가 선택한 두 번째보기 컨트롤러에서 텍스트를 포함하는 변수를 갖고 싶습니다. 어떻게해야합니까? 직접 전달하려고 시도했지만 어떤 이유로 작동하지 않습니다.UITableViewController에 속성을 전달하는 가장 간단한 방법

답변

0

받는 viewcontroller (이 경우에는 SecondTableViewController라고 부름)에서 속성 (예 : selectedText - NSString)을 선언하십시오. SecondTableViewController.h에서

: SecondTableViewController.m에서

@interface SecondTableViewController : UITableViewController { 

} 

@property(nonatomic, strong) NSString *selectedText; 

: 당신의 FirstTableViewController.m에서

@implementation SecondTableViewController 
@synthesize messageDetail; 

:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    // Make sure we are dealing with the proper Segue 
    if ([segue.identifier isEqualToString:@"idOfMySegue"]) { 
     SecondTableViewController *svc = segue.destinationViewController; 
     svc.selectedText = myVarValue; // This can be got from either setting another var in the tableviewcontroller or by just passing the entire object at the selected index of the NSIndexPath.row (if you are populating the tableview with an array. Note you would change the object type of the passed along object from an NSString to whatever the other object is. 
    } 
} 

prepareForSeque 방법이 여기에 코드입니다 한 뷰에서 다른 뷰로 데이터 나 오브젝트를 전달합니다.

+0

유일한 문제는 당신이 만약 당신의 FirstTableViewController.m 파일 – blake305

+0

어떤 클래스 속성에 액세스 할 수 있습니다 지금 가지고있는 것을 보내 주시면 문제를 파악하는 데 도움을 드리겠습니다. –

+0

에 SecondTableViewController에 대한 참조를 포함 나는이 prepareForSegue 안에 당신은 한 사람에 액세스 할 수 있습니다 (prepareForSegue가에 입력 클래스) –

관련 문제