Initialising an NSTableView - objective-c

I'm quite new to Cocoa and I am trying to setup a table view backed by an array. I've setup the app delegate as the datasource for the tableview, and implemented NSTableViewDataSource protocol.
When I run the app, I get the following log output:
2012-06-23 18:25:17.312 HelloWorldDesktop[315:903] to do list is nil
2012-06-23 18:25:17.314 HelloWorldDesktop[315:903] Number of rows is 0
2012-06-23 18:25:17.427 HelloWorldDesktop[315:903] App did finish
launching
I thought that when I called reloadData on the tableView it would call numberOfRowsInTableView:(NSTableView *)tableView again to refresh the view, but that doesn't seem to be happening. What have I missed?
My .h and .m listings are below.
AppDelegate.h
#import <Cocoa/Cocoa.h>
#interface AppDelegate : NSObject <NSApplicationDelegate, NSTableViewDataSource>
#property (assign) IBOutlet NSWindow *window;
#property (assign) IBOutlet NSTableView * toDoListTableView;
#property (assign) NSArray * toDoList;
#end
AppDelegate.m
#import "AppDelegate.h"
#implementation AppDelegate
#synthesize window = _window;
#synthesize toDoList;
#synthesize toDoListTableView;
- (void)dealloc
{
[self.toDoList dealloc];
[super dealloc];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSLog(#"App did finish launching");
// Insert code here to initialize your application
// toDoList = [[NSMutableArray alloc] init];
toDoList = [[NSMutableArray alloc] initWithObjects:#"item 1", #"item 2", nil];
[self.toDoListTableView reloadData];
// NSLog(#"table view %#", self.toDoListTableView);
}
//check toDoList initialised before we try and return the size
- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView {
NSInteger count = 0;
if(self.toDoList){
count = [toDoList count];
} else{
NSLog(#"to do list is nil");
}
NSLog(#"Number of rows is %ld", count);
return count;
}
-(id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSLog(#"in objectValueForTable");
id returnVal = nil;
NSString * colId = [tableColumn identifier];
NSString * item = [self.toDoList objectAtIndex:row];
if([colId isEqualToString:#"toDoCol"]){
returnVal = item;
}
return returnVal;
}
#end

The first thing that I'd check is that you're NSTableView IBOutlet is still set in applicationDidFinishLaunching.
NSLog(#"self.toDoListTableView: %#", self.toDoListTableView)
You should see output like:
<NSTableView: 0x178941a60>
if the outlet is set properly.
If you see 'nil' rather than an object, double check to ensure that your NSTableView is connected to your outlet in the XIB editing mode of Xcode. Here's a documentation link for assistance connecting outlets.

I fixed it - I'd set the appDelegate as the datasource and the delegate for the tableView but ctrl-dragging from the tableView to the appDelegate, but I hadn't ctrl-dragged the other way to actually link up the outlet I'd declared with the table view. It's working now. Thanks for your help though Jeff.

Related

Populate NSTableView with a new object by clicking a button

Im trying to populate an NSTableView with a custom object by clicking a button. My custom class has just NSString properties: title and volume. I customized the init method to create an object and add it to my array that is hooked up to my table view. Then on the method for my button I had it create another object and add it to the array. When I run the program the object from the init method does display correctly. However, when I click my button I get nothing.
Here is the code for my header file:
#import <Cocoa/Cocoa.h>
#interface AppDelegate : NSObject <NSApplicationDelegate, NSTableViewDataSource>{
NSMutableArray *_myArray;}
#property (weak) IBOutlet NSTableView *tableView;
- (IBAction)button:(id)sender;
#end
and here is my implementation:
#import "AppDelegate.h"
#import "trade.h"
#interface AppDelegate ()
#property (weak) IBOutlet NSWindow *window;
#end
#implementation AppDelegate
-(id)init{
self = [super init];
if (self){
_myArray = [[NSMutableArray alloc]init];
trade *firstTrade = [[trade alloc]init];
[firstTrade setTitle:#"Trade One"];
[firstTrade setVolume:#"Volume 01"];
[_myArray addObject:firstTrade];}
return self;}
- (IBAction)button:(id)sender {
trade *secondTrade = [[trade alloc]init];
[secondTrade setTitle:#"Trade two"];
[secondTrade setVolume:#"Volume 02"];
[_myArray addObject:secondTrade];
[_tableView reloadData];}
-(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView{
return _myArray.count;}
-(id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
if ([tableColumn.identifier isEqualToString:#"Title"]){
trade *item = [_myArray objectAtIndex:row];
return item.title;
}else{
trade *item = [_myArray objectAtIndex:row];
return item.volume;}}
#end
Not sure what I'm doing wrong here as what I did in the init method is pretty much the same thing I did in button method. Any help is greatly appreciated. Here is a picture of the program after I run it:
tableView program
As you can see my first object appears in the table view, but not the second.
While looking at this project I duplicated the [_tableView reloadData]; line and placed a breakpoint on the second one so I could see what was going on right after the first one is called. One thing I noticed is that _myArray does now contain 2 objects after the button click.
However, when I look into _tableView it shows that _myArray only contains 1 object. How is it that the object is actually getting added but the table view is only getting 1?
Here is a picture for reference:Debug

Mac OSX Storyboard : communicate between NSViewController

I use storyboard in a OS X cocoa application project with a SplitView controller and 2 others view controller LeftViewController and RightViewController.
In the LeftViewController i have a tableView that display an array of name. The datasource and delegate of the tableview is the LeftViewController.
In the RightViewController i just have a centered label that display the select name. I want to display in the right view the name selected in the left view.
To configure the communication between the 2 views controllers i use the AppDelegate and i define 2 property for each controller in AppDelegate.h
The 2 property are initialized in the viewDidLoad of view controller using the NSInvocation bellow :
#implementation RightViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
id delg = [[NSApplication sharedApplication] delegate];
SEL sel1 = NSSelectorFromString(#"setRightViewController:");
NSMethodSignature * mySignature1 = [delg methodSignatureForSelector:sel1];
NSInvocation * myInvocation1 = [NSInvocation
invocationWithMethodSignature:mySignature1];
id me = self;
[myInvocation1 setTarget:delg];
[myInvocation1 setSelector:sel1];
[myInvocation1 setArgument:&me atIndex:2];
[myInvocation1 invoke];
}
I have the same in LeftViewController.
Then if i click on a name in the table view, i send a message to the delegate with the name in parameter and the delegate update the label of the RightViewController with the given name. It works fine but according to apple best practice it’s not good.
Is there another way to communicate between 2 view controller inside a storyboard ?
I've already read a lot of post but found nothing for OS X.
You can download the simple project here : http://we.tl/4rAl9HHIf1
This is more advanced topic of app architecture (how to pass data).
Dirty quick solution: post NSNotification together with forgotten representedObject:
All NSViewControllers have a nice property of type id called representedObject. This is one of the ways how to pass data onto NSViewController. Bind your label to this property. For this simple example we will set representedObject some NSString instance. You can use complex object structure as well. Someone can explain in comments why storyboards stopped to show representedObject (Type safety in swift?)
Next we add notification observer and set represented object in handler.
#implementation RightViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserverForName:#"SelectionDidChange" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
//[note object] contains our NSString instance
[self setRepresentedObject:[note object]];
}];
}
#end
Left view controller and its table:
Once selection changes we post a notification with our string.
#interface RightViewController () <NSTableViewDelegate, NSTableViewDataSource>
#end
#implementation RightViewController
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
return [[self names] count];
}
- (nullable id)tableView:(NSTableView *)tableView objectValueForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row
{
return [self names][row];
}
- (NSArray<NSString *>*)names
{
return #[#"Cony", #"Brown", #"James", #"Mark", #"Kris"];
}
- (void)tableViewSelectionDidChange:(NSNotification *)notification
{
NSTableView *tableView = [notification object];
NSInteger selectedRow = [tableView selectedRow];
if (selectedRow >= 0) {
NSString *name = [self names][selectedRow];
if (name) {
[[NSNotificationCenter defaultCenter] postNotificationName:#"SelectionDidChange" object:name];
}
}
}
PS: don't forget to hook tableview datasource and delegate in storyboard
Why is this solution dirty? Because once your app grows you will end up in notification hell. Also view controller as data owner? I prefer window controller/appdelegate to be Model owner.
Result:
AppDelegate as Model owner.
Our left view controller will get it's data from AppDelegate. It is important that AppDelegate controls the data flow and sets the data (not the view controller asking AppDelegate it's table content cause you will end up in data synchronization mess). We can do this again using representedObject. Once it's set we reload our table (there are more advanced solutions like NSArrayController and bindings). Don't forget to hook tableView in storyboard. We also modify tableview's delegate methos the tableViewSelectionDidChange to modify our model object (AppDelegate.selectedName)
#import "LeftViewController.h"
#import "AppDelegate.h"
#interface LeftViewController () <NSTableViewDelegate, NSTableViewDataSource>
#property (weak) IBOutlet NSTableView *tableView;
#end
#implementation LeftViewController
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
return [[self representedObject] count];
}
- (nullable id)tableView:(NSTableView *)tableView objectValueForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row
{
return [self representedObject][row];
}
- (void)setRepresentedObject:(id)representedObject
{
[super setRepresentedObject:representedObject];
//we need to reload table contents once
[[self tableView] reloadData];
}
- (void)tableViewSelectionDidChange:(NSNotification *)notification
{
NSTableView *tableView = [notification object];
NSInteger selectedRow = [tableView selectedRow];
if (selectedRow >= 0) {
NSString *name = [self representedObject][selectedRow];
[(AppDelegate *)[NSApp delegate] setSelectedName:name];
} else {
[(AppDelegate *)[NSApp delegate] setSelectedName:nil];
}
}
In RightViewController we delete all code. Why? Cause we will use binding AppDelegate.selectedName <--> RightViewController.representedObject
#implementation RightViewController
#end
Finally AppDelegate. It needs to expose some properties. What is interesting is how do I get my hands on all my controllers? One way (best) is to instantiate our own window controller and remember it as property. The other way is to ask NSApp for it's windows (be careful here with multiwindow app). From there we just ask contentViewController and loop through childViewControllers. Once we have our controllers we just set/bind represented objects.
#interface AppDelegate : NSObject <NSApplicationDelegate>
#property (nonatomic) NSString *selectedName;
#property (nonatomic) NSMutableArray <NSString *>*names;
#end
#import "AppDelegate.h"
#import "RightViewController.h"
#import "LeftViewController.h"
#interface AppDelegate () {
}
#property (weak, nonatomic) RightViewController *rightSplitViewController;
#property (weak, nonatomic) LeftViewController *leftSplitViewController;
#property (strong, nonatomic) NSWindowController *windowController;
#end
#implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
_names = [#[#"Cony", #"Brown", #"James", #"Mark", #"Kris"] mutableCopy];
_selectedName = nil;
NSStoryboard *storyboard = [NSStoryboard storyboardWithName:#"Main"
bundle:[NSBundle mainBundle]];
NSWindowController *windowController = [storyboard instantiateControllerWithIdentifier:#"windowWC"];
[self setWindowController:windowController];
[[self windowController] showWindow:nil];
[[self leftSplitViewController] setRepresentedObject:[self names]];
[[self rightSplitViewController] bind:#"representedObject" toObject:self withKeyPath:#"selectedName" options:nil];
}
- (RightViewController *)rightSplitViewController
{
if (!_rightSplitViewController) {
NSArray<NSViewController *>*vcs = [[[self window] contentViewController] childViewControllers];
for (NSViewController *vc in vcs) {
if ([vc isKindOfClass:[RightViewController class]]) {
_rightSplitViewController = (RightViewController *)vc;
break;
}
}
}
return _rightSplitViewController;
}
- (LeftViewController *)leftSplitViewController
{
if (!_leftSplitViewController) {
NSArray<NSViewController *>*vcs = [[[self window] contentViewController] childViewControllers];
for (NSViewController *vc in vcs) {
if ([vc isKindOfClass:[LeftViewController class]]) {
_leftSplitViewController = (LeftViewController *)vc;
break;
}
}
}
return _leftSplitViewController;
}
- (NSWindow *)window
{
return [[self windowController] window];
}
//VALID SOLUTION IF YOU DON'T INSTANTIATE STORYBOARD
//- (NSWindow *)window
//{
// return [[NSApp windows] firstObject];
//}
#end
Result: works exactly the same
PS: If you instantiate own window Controller don't forget to delete initial controller from Storyboard
Why is this better? Cause all changes goes to model and models sends triggers to redraw views. Also you will end up in smaller view controllers.
What can be done more? NSObjectController is the best glue between your model objects and views. It also prevents retain cycle that sometimes can happen with bindings (more advanced topic). NSArrayController and so on...
Caveats: not a solution for XIBs
I managed to get what i want by adding the following code in AppDelegate.m :
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
//
NSStoryboard *storyboard = [NSStoryboard storyboardWithName:#"Main"
bundle:[NSBundle mainBundle]];
self.windowController = [storyboard instantiateControllerWithIdentifier:#"windowController"];
self.window = self.windowController.window;
self.splitViewController = (NSSplitViewController*)self.windowController.contentViewController;
NSSplitViewItem *item0 = [self.splitViewController.splitViewItems objectAtIndex:0];
NSSplitViewItem *item1 = [self.splitViewController.splitViewItems objectAtIndex:1];
self.leftViewController = (OMNLeftViewController*)item0.viewController;
self.rightViewController = (OMNRightViewController*)item1.viewController;
[self.window makeKeyAndOrderFront:self];
[self.windowController showWindow:nil];
}
We also need to edit the storyboard NSWindowController object as follow :
Uncheck the checkbox 'Is initial controller' because we add it programmatically in AppDelegate.m.
Now the left and right view can communicate. Just define a property named rightView in OMNLeftViewController.h :
self.leftViewController.rightView = self.rightViewController;

NStableview setDatasource EXC_BAD_ACCESS

Im trying to just create a simple menu with an NSTableView using an NSarray. When i set the data source to the class i created i get EXC_BAD_ACCESS error. Wierd thing is, it worked in macruby?
implementation file:
#implementation TableArray
- (id) init
{
self = [super init];
if(self) {
arr = [NSArray arrayWithObjects:#"hey", #"what", #"there", nil];
}
return self;
}
- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView
{
return [arr count];
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
return [arr objectAtIndex:rowIndex];
}
#end
Header:
#interface TableArray: NSObject <NSTableViewDataSource> {
NSArray *arr;
}
- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView;
- (id) tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex;
#end
And in the app delegate:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
TableArray *arr = [[TableArray alloc] init];
[tv setDataSource:arr];
[tv reloadData];
}
And the delegate header:
#import <Cocoa/Cocoa.h>
#interface AppDelegate : NSObject <NSApplicationDelegate> {
IBOutlet NSTableView *tv;
}
#property (assign) IBOutlet NSWindow *window;
#end
I'm betting you have ARC enabled (possibly GC). NSTableView maintains a weak reference to its data source and you aren't maintaining a strong reference to same, so ARC is releasing your data source before you are done with.
Note that it is exceptionally rare to have a data source float about like this. It is almost assuredly a part of the control layer of your app since the data source is the conduit between the table and the underlying data store.
It likely works under MacRuby because the code is slightly different or because of implementation details.
It would be useful to know where you are initializing *tv. I'm assuming you've placed it in some NIB file that gets loaded at app startup.
Then, you should put IBOutlet NSTableView *tv; in a ViewController, ideally one that subclasses UITableViewController. a tableView reference/outlet belongs there.
Also, it would be easier to use the viewController itself as dataSource, and make the connection in Interface Builder.

Datasource not returned by sub class of parent class implementing UITableView, throwing exception

I want to show some media of different categories (e.g. mostViewed, starred) in a UITableView. I created APPParentViewController which implements UITableViewDataSource and UITableViewDelegate protocol. In cellForRowAtIndexPath method in APPParentViewController, I return the appropriate cell which is filled with data coming from an array.
The array is actually instantiated in the init method in a sub class of APPParentViewController, which I exemplarily called APPChildViewController. There is one APPChildViewController for each media category. They just differ in the way the array is instantiated, the content of the array so to say.
I instantiate all APPChildViewController classes in another UIViewController ([[APPChildViewController alloc] init]) and then initially select one APPChildViewController to view (all happens in viewDidLoad method of that UIViewController). Working so far.
But when I want to show another APPChildViewController simply by removing the old view and adding the requested view (when the user requested it by pressing a button), I am getting the following exception:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' ***
This is the code I am using (I removed everything which is not important in my opinion, so I hope it's still comprehensible):
APPParentViewController.h
#import <UIKit/UIKit.h>
#interface APPParentViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
#property (strong, nonatomic) NSArray *media;
#property (strong, nonatomic) UITableView *tableView;
#end
APPParentViewController.m
#import "APPParentViewController.h"
#import "APPCell.h"
#interface APPParentViewController ()
#end
#implementation APPParentViewController
#synthesize media;
#synthesize tableView;
-(void)viewDidLoad
{
self.tableView = [[UITableView alloc] init];
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.media count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellTableIdentifier = #"CellTableIdentifier";
static BOOL nibsRegistered = NO;
if (!nibsRegistered) {
UINib *nib = [UINib nibWithNibName:#"APPCell" bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:CellTableIdentifier];
nibsRegistered = YES;
}
APPCell *cell = [self.tableView dequeueReusableCellWithIdentifier: CellTableIdentifier];
NSUInteger row = [indexPath row];
NSDictionary *rowData = [self.media objectAtIndex:row];
cell.title = [rowData objectForKey:#"Title"];
return cell;
}
#end
APPChildViewController.h
#import "APPParentViewController.h"
#interface APPChildViewController : APPParentViewController
#end
APPChildViewController.m
#import "APPChildViewController.h"
#import "APPCell.h"
#interface APPChildViewController ()
#end
#implementation APPChildViewController
- (id)init
{
self = [super init];
if (self) {
self.media = fill array...
}
return self;
}
It actually works when I copy the cellForRowAtIndexPath method implementation to all sub classes, but this is obviously not the way inheritance is intended to work...
When you make the switch, some cells will have a reference to the old child's media, and if that object is gone uh oh:
NSDictionary *rowData = [self.media objectAtIndex:row];
As soon so make the switch of dataSource, are you sending:
[self.tableView reloadData];
I'm assuming (hoping!) that you have just the one nib owned by the parent...

changing UILabel text on a subview from main view

Ok, so I'm a relative noob with Objective-C/iOS programming, so hopefully someone with more knowledge here can help me out.
I have an iPad application using the SplitViewController template (with Core Data). I created another UIViewController (with xib file) called PlayerViewController. This View has several UILabel components on it.
I have a list of players that show up in the RootViewController (UITableView) and when you select a player, I programmatically create a PlayerViewController (in DetailViewController), pass it the NSManagedObject that was passed to the DetailViewController, try to set the text of one of the labels on the PlayerViewController's view, and then add it as a subview to the DetailViewController.
All of this works great except for the setting the text of the label on the PlayerViewController's view. I'm not sure what I'm doing wrong. I have used NSLog to confirm that the NSManagedObject is not nil and that the NSManagedObject property I'm trying to use has the correct text.
I'm at a loss here. Any help would be greatly appreciated. (Code follows):
This method is in the DetailViewController.m file:
- (void)configureView {
// Update the user interface for the detail item.
PlayerViewController *player = [[PlayerViewController alloc] init];
player.player = detailItem;
[self.view addSubview:player.view];
}
This method is called when the user selects an item from the RootViewController (This functionality, calling of configureView, is setup by the template and I haven't changed it).
Setting the player property of the PlayerViewController to object detailItem is handled in the setPlayer method of that class.
- (void)setPlayer:(NSManagedObject *)managedObject {
if (player != managedObject) {
[player release];
player = [managedObject retain];
// Update the view.
[self configureView];
}
}
I then have a configureView method as well in PlayerViewController that sets the text of the label:
- (void)configureView {
nickName.text = [[player valueForKey:#"Nickname"] description];
NSLog(#"Nickname %#", [[player valueForKey:#"Nickname"] description]);
NSLog(#"Nickname %#", nickName.text);
}
Ok, so the first NSLog statement prints the desired value, but the text of the UILabel (called nickName) returns nil.
The following is the full PlayerViewController.h & .m files:
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
/*
When setting the player item, update the view
*/
- (void)setPlayer:(NSManagedObject *)managedObject {
if (player != managedObject) {
[player release];
player = [managedObject retain];
// Update the view.
[self configureView];
}
}
- (void)configureView {
nickName.text = [[player valueForKey:#"Nickname"] description];
NSLog(#"Nickname %#", [[player valueForKey:#"Nickname"] description]);
NSLog(#"Nickname %#", nickName.text);
}
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
I'm sure I'm just missing something trivial, but I can't figure it out, and haven't been able to find any answers searching the web.
Thanks for any help!
Ok, so after playing with this for a bit and searching and searching around, I have gotten the answer to my problem. It turns out all the code I had was fine except the location of one statement. My call to configureView in PlayerViewController.m needed to be in viewDidLoad() not in the setPlayer() method. It all works great now.
Change the configureView method to that :
- (void)configureView {
nickName.text = (NSString*)[player valueForKey:#"Nickname"];
}
Yes, better place to call method is
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self configureView];
}
(void)setPlayer:(NSManagedObject *)managedObject called before your nib files loaded.