2014-08-27 4 views
1

Xcode5 및 IOS7에서 새로운 기능으로 두 개의 레이블과 이미지의 텍스트를 업데이트하는 데 문제가 있습니다. NavigationController ->InitialViewController (사용자 정의 행이있는 UITableView) 행을 클릭하면 이전 RowCell의 정보로 UIViewController을 표시하려고하는데이 정보는 NSDictionary으로 채워진 에 저장됩니다 (이름, 팀 , 이미지). 문제는 뷰가 레이블과 이미지의 텍스트를 업데이트하지 않고 아래 코드에서 무엇이 잘못되었는지를 발견 할 수 없다는 것입니다. 나는 그것이 pushView까지 일하고 있다는 것을 디버깅했는데, 레이블 내부의 정보와 이미지가 업데이트되지 않습니다.NSDictionary로 뷰 컨트롤러의 레이블 업데이트

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    NSDictionary *playersVC = [players objectAtIndex:indexPath.row]; 

    ProfilePlayerViewController *profile = [self.storyboard instantiateViewControllerWithIdentifier:@"ProfilePlayerViewController"]; 

    [self.navigationController pushViewController:profile animated:YES]; 
    [profile.playerName setText:[playersVC objectForKey:@"name"]]; 
    [profile.teamName setText:[playersVC objectForKey:@"team"]]; 
    [profile.playerImage setImage:[UIImage imageNamed:[playersVC objectForKey:@"image"]]]; 
} 

나머지 구성은 옳은 것 같습니다. 저는 IOS5의 튜토리얼의 일부를 따르고 있습니다.

+0

보기 컨트롤러를 열기 전에 프로필의 속성을 설정해 보았습니까? – Mike

+0

나는 선수가 VC가 0이 될 것이라고 장담 할 것이다. –

+0

예, playerName, teamName 및 playerImage를 설정했습니다. 덕분에 –

답변

2

이렇게하면 작동하지 않습니다. ProfilePlayerViewController에 @property NSDictionary를 만들어야합니다. 그런 다음 첫 번째 View Controller에서 행을 클릭하면 해당 NSDictionary를 다음과 같은 해당 속성에 할당합니다.

NSDictionary *playersVC = [players objectAtIndex:indexPath.row]; 
ProfilePlayerViewController *profile = [self.storyboard instantiateViewControllerWithIdentifier:@"ProfilePlayerViewController"]; 
profile.myDictionary = playersVC ; 

이제 ProfilePlayerViewController의 ViewDidLoad 메서드에서 레이블과 이미지를 업데이트하십시오. 확실히 작동 할 것입니다. 희망이 도움이됩니다. 설정,

ProfilePlayerViewController *profile = [self.storyboard instantiateViewControllerWithIdentifier:@"ProfilePlayerViewController"]; 

[self.navigationController pushViewController:profile animated:YES]; 
profile.playerName = [playersVC objectForKey:@"name"]; 
profile.team = [playersVC objectForKey:@"team"]; 
profile.imageName = [playersVC objectForKey:@"image"]; 

그리고 당신의 [self viewDidLoad] 방법 :

+0

이 대부분 맞지만 myDictionary 값은 viewDidLoad 메서드 호출시 업데이트되지 않을 수 있습니다. 이런 것들을보기에 넣기에 가장 좋습니다 .WillAppear. – d2burke

+0

나는 당신이 제안한 변경을했고 그것은 완벽하게 작동한다 Ayon !! 고마워. –

+0

예, 당신 말이 맞아요. @ d2burke – ayon

0

봅니다이 ViewController를 인스턴스화 한 후, 사전에서, 그래서 같이 이러한 속성을 설정하여 ProfilePlayerViewController

@property (nonatomic,strong) NSString *playerName; 
@property (nonatomic,strong) NSString *team; 
@property (nonatomic,strong) NSString *imageName; 

같은 인스턴스 변수를 만들려면 귀하의 UI 요소.

-(void)viewDidLoad { 
     [super viewDidLoad]; 
     self.playerNameLabel.text = self.playerName; 
     self.teamLabel.text = self.team; 
     [self.playerImage setImage:[UIImage imageNamed:self.imagName]]; 
} 

이렇게하면 문제가 해결됩니다.