Ok, so I am a relative noob with Objective-C / iOS programming, so hopefully someone with more knowledge here can help me.
I have an iPad application using the SplitViewController template (with master data). I created another UIViewController(with xib file) called PlayerViewController. This view has several components UILabel.
I have a list of players that appear in RootViewController ( UITableView), and when you select a player, I programmatically create a PlayerViewController (in DetailViewController), pass it to it NSManagedObject, which was passed to DetailViewController, try setting the text of one of the labels in the PlayerViewController, and then add its as a sub-view in DetailViewController.
All this works fine except for setting the shortcut text in the PlayerViewController. I'm not sure what I'm doing wrong. I used NSLogto confirm that NSManagedObjectit is not equal to zero and that the property NSManagedObjectthat I am trying to use has the correct text.
I don’t get it here. Any help would be greatly appreciated. (Code follows):
This method is located in the file DetailViewController.m:
- (void)configureView {
PlayerViewController *player = [[PlayerViewController alloc] init];
player.player = detailItem;
[self.view addSubview:player.view];
}
, RootViewController ( , configureView, , ).
PlayerViewController detailItem setPlayer .
- (void)setPlayer:(NSManagedObject *)managedObject {
if (player != managedObject) {
[player release];
player = [managedObject retain];
[self configureView];
}
}
configureView PlayerViewController, :
- (void)configureView {
nickName.text = [[player valueForKey:@"Nickname"] description];
NSLog(@"Nickname %@", [[player valueForKey:@"Nickname"] description]);
NSLog(@"Nickname %@", nickName.text);
}
, NSLog , UILabel ( nickName) nil.
PlayerViewController.h .m:
PlayerViewController.h:
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
@interface PlayerViewController : UIViewController {
NSManagedObject *player;
IBOutlet UILabel *nickName;
IBOutlet UILabel *goalCount;
IBOutlet UILabel *assistCount;
IBOutlet UILabel *timeInGame;
}
@property (nonatomic, retain) IBOutlet UILabel *nickName;
@property (nonatomic, retain) IBOutlet UILabel *goalCount;
@property (nonatomic, retain) IBOutlet UILabel *assistCount;
@property (nonatomic, retain) IBOutlet UILabel *timeInGame;
@property (nonatomic, retain) NSManagedObject *player;
@end
PlayerViewController.m:
#import "PlayerViewController.h"
@implementation PlayerViewController
@synthesize nickName, goalCount, assistCount, timeInGame, player;
#pragma mark -
#pragma mark Managing the detail item
- (void)setPlayer:(NSManagedObject *)managedObject {
if (player != managedObject) {
[player release];
player = [managedObject retain];
[self configureView];
}
}
- (void)configureView {
nickName.text = [[player valueForKey:@"Nickname"] description];
NSLog(@"Nickname %@", [[player valueForKey:@"Nickname"] description]);
NSLog(@"Nickname %@", nickName.text);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)dealloc {
[super dealloc];
}
@end
, - , .
!