2013-04-06 6 views
0

내 iOS 앱 프로젝트에 문제가 있습니다. 내 SearchViewController 값을 내 ResultGeneralInfoViewController로 전송하고 싶습니다. 버그 나 문제는 없지만 작동하지 않습니다. 여기viewcontrollers 사이에 변수 전송

내 SearchViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSDictionary *item = [searchResults objectAtIndex:[indexPath row]]; 


    ResultGeneralInfosViewController *detailViewController = [ResultGeneralInfosViewController alloc]; 
    detailViewController.companyName = [item objectForKey:@"companyName"]; 
    NSLog([item objectForKey:@"companyName"]); 
} 

ResultGeneralInfoViewController.h

@interface ResultGeneralInfosViewController : UIViewController { 

    NSString *companyName; 
} 

@property NSString *companyName; 

@property (weak, nonatomic) IBOutlet UILabel *companyNameLabel; 

및 ResultGeneralInfoViewController.m

@implementation ResultGeneralInfosViewController 

@synthesize companyName; 

//Outlets 
@synthesize companyNameLabel; 


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 

    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    companyNameLabel.text = self.companyName; 
} 

어떤 아이디어를 내 코드?

+1

* "버그는 없지만 작동하지 않습니다."* 나에게 모순이있는 것처럼 보입니다 :-) –

답변

4

ResultGeneralInfosViewController를 초기화하지 않았으며 할당 한 것입니다. 먼저 init 메소드를 호출하여 초기화하십시오. 예를 들어,

ResultGeneralInfosViewController *detailViewController = 
    [[ResultGeneralInfosViewController alloc] initWithNibName:@"NibName" bundle:nil]; 

개체가 초기화 된 후에 속성을 설정해야합니다.

+0

예, 맞습니다! –

+0

내 SearchViewController.m에 코드를 추가했지만 그 결과는 그대로 유지됩니다. (내 NibName은 무엇입니까? – DerFuchs10

+0

NibName은보기 컨트롤러와 연결된 nib 파일의 이름입니다. –

1

didSelectRowAtIndexPath에서 ResultGeneralInfosViewController의 인스턴스를 만들지 만 사용자가 아무 작업도 수행하지 않습니다. 내비게이션 컨트롤러를 사용하는 경우 추가해야합니다.

[self.navigationController pushViewController:detailViewController animated:YES];