A few IBOutlets pointing to nil - ios

After a long while I've finally started working with Objective-C again, on my only complete app so far. The goal is to eventually refactor for ARC and possibly storyboards, but for the time being I'm polishing the iOS 4.x target. I am quite rusty, so bar with me if this is a stupid question.
I have a button in my main view that triggers the showAction method. The method is as follows:
- (void)showAbout
{
AboutViewController *aboutView = [[[AboutViewController alloc] init] autorelease];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
aboutView.modalPresentationStyle = UIModalPresentationFormSheet;
}
else
{
aboutView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
}
[self presentModalViewController:aboutView animated:YES];
}
The AboutViewController class has this .h:
#interface AboutViewController : UIViewController <UIActionSheetDelegate, MFMailComposeViewControllerDelegate> {
}
- (IBAction)dismiss:(UIButton *)sender;
- (IBAction)feedback:(UIButton *)sender;
#property (retain) IBOutlet UIButton *dismissButton;
#property (retain) IBOutlet UIButton *feedbackButton;
#property (retain) IBOutlet UIImageView *background;
#property (retain) IBOutlet UITextView *textView;
#end
and everything has been connected properly in the .xib file (the same one for iPhone and iPad). The actions are triggered as expected, and the outlets are accessible, but only on iPhone. When running on iPad, only textView is properly initialized, and all the rest points to nil.
In the .m I have tried this:
#implementation AboutViewController
#synthesize dismissButton = _dismissButton;
#synthesize feedbackButton = _feedbackButton;
#synthesize background = _background;
#synthesize textView = _textView;
// ...
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(#"obj self.dismiss: %#", self.dismissButton);
NSLog(#"frame dismiss: %#", NSStringFromCGRect(self.dismissButton.frame));
}
On iPhone I get this:
2012-02-08 22:51:00.341 myapp[17290:207] obj self.dismiss: <UIButton: 0x70281d0; frame = (180 410; 120 30); opaque = NO; autoresize = LM+W+RM+TM; layer = <CALayer: 0x7028260>>
2012-02-08 22:51:00.342 myapp[17290:207] frame dismiss: {{180, 410}, {120, 30}}
On iPad, instead, I get this:
2012-02-08 22:51:40.428 myapp[17320:207] obj self.dismiss: (null)
2012-02-08 22:51:40.428 myapp[17320:207] frame dismiss: {{0, 0}, {0, 0}}
There is nothing else that happens depending on the UI Idiom, and I'm really confused about this. It's as if on the iPad the outlets for anything other than textView are not set, even though they are correctly linked up in the .xib file. In viewWillAppear, self.textView is working as expected also on iPad. I also tried doing this in viewDidLoad, which should be called before viewWillAppear if I'm not mistaken, and even in the dismiss: method, but they are just never available.
The reason I need to access the buttons' frames is that the about view is relatively complex and fails to reposition its subviews automatically. The only thing I need to do is make the buttons wider on the larger modal view on iPad.
Any hints would be greatly appreciated!
Thanks in advance.

Did you ever have a separate .xibs for iPad and iPhone? If so you might have the same issue I had. That is until #AliSoftware dropped some knowledge on me:
UIView in nib is nil on iPad, and not nil on iPhone
Essentially you need to:
Delete the Build Products Directory
Delete your app from all your simulators
Build and Run
I believe the problem is that a ghost .xib for iPad was hanging around causing issues. Truly wiping the apps clean did the trick. Good luck!

Related

Adding tag after switching view controllers

I have a randomly generated int that I assign to a tag for a UIImageView on my storyboard in ViewWillAppear.
When I segue to the main menu and try to enter the view again, however, the app crashes. I know it's because of the tag because when I remove it everything works fine.
Any thoughts on why it works the first time but not on times after that? Code below.
ViewController.h:
#interface ViewController : UIViewController{
int tagnumber;
IBOutlet UIImageView *box;
...
}
ViewController.m:
-(void)viewWillAppear:(BOOL)animated{
tagnumber = arc4random()%1000;
box.tag = tagnumber;
...
}
- (IBAction)unwindToThisViewController:(UIStoryboardSegue *)unwindSegue
{
[_animator removeAllBehaviors];
[box removeFromSuperview];
}
MainMenu.m:
-(IBAction)prepareForUnwind:(UIStoryboardSegue *)segue {
}
Basically, when the view disappears and the system is running out of memory, it will call on UIViewController's implementation of didReceiveMemoryWarning. There is a fantastic description of this here: ViewWillDisappear versus dealloc
When you are creating an IBOutput you should really have a weak pointer to it by saying #property (weak, nonatomic) IBOutlet UIImageView *box. Views retain their subviews, and therefore, if a view gets deallocated, its subviews retain count decreases by one. When the view disappears, the system will decide when to deallocate self.view, and when it does, it will automatically release box, and box will get deallocated as well. You don't really need to worry about it.

Updating label text doesn't work until I reload the UIView

I am struggling with an issue which I simply do not understand. Here is the following scenario:
I try to create a multi-view wizard in iOS. After much consideration I decided to go with an approach that may not be ideal but will help me keep the code clean. I don't want to chain ten view controllers and manage the manually.
The wizard has one view controller. At start it loads a certain amount of UIView's into the view and allows me to scroll left and right. Code below.
The UIViews are created in interface builder and I have one XIB file containing all the views.
Each UIView has more IBOutlets (for example a label) which are connected to the File Owner, in this case the wizard view controller.
This all works really well EXCEPT for the fact that the labels on the loaded UIViews don't update. Here is the problem:
I call the wizard and it loads all UIViews as well as Outlets right then
I skip through the wizard.
But then the problem occurs:
Example:
Step 2 has a button to call the address book (which works)
The Address book opens, returns an object (which works)
But my Label on UIView "Step 2" doesn't update when I assign a value.
Only after I remove this UIView from the Wizard and add it back, it works. It seems to me that the UIView loads correctly but any subsequent changes to their outlets don't work.
By the way, I verified that the label as well as the buttons and everything is connected probably. I just cannot update the label when its loaded as part of the XIB and the value changes after the initial load.
Code:
Wizard loading UIViews:
-(void)configureWizard
{
self.showsHorizontalScrollIndicator = NO;
self.showsVerticalScrollIndicator = NO;
self.scrollEnabled = NO;
self.contentSize = CGSizeMake(CGRectGetWidth(self.frame) * [wizardDelegate numberOfSteps], CGRectGetHeight(self.frame));
self.delegate = self;
}
-(void)loadWizard
{
[self configureWizard];
[self updateNavButtonsIfNecessary];
currentIndex = 0;
for (int i = 0; i<[wizardDelegate numberOfSteps]; i++)
{
[self loadWizardStepAtIndex:i];
}
}
- (void)loadWizardStepAtIndex:(int)index {
CGRect frame = self.frame;
frame.origin.x = CGRectGetWidth(frame) * index;
frame.origin.y = 0;
UIView *view = [wizardDelegate viewForStepAtIndex:index];
view.frame = frame;
[self addSubview:view];
}
Wizard Main View Controller.h (File Owner)
#property (strong, nonatomic) IBOutlet UIView *memberwizard_1;
#property (strong, nonatomic) IBOutlet UIView *memberwizard_2;
#property (strong, nonatomic) IBOutlet UIView *memberwizard_3;
#property (strong, nonatomic) IBOutlet UIView *memberwizard_4;
#property (strong, nonatomic) IBOutlet UIView *memberwizard_5;
#property (strong, nonatomic) IBOutlet UIView *memberwizard_6;
#property (strong, nonatomic) IBOutlet UIView *memberwizard_7;
#property (strong, nonatomic) IBOutlet UIButton *wizard2_lookupExistingContact;
#property (strong, nonatomic) IBOutlet UILabel *wizard2_nameLabel;
Wizard Main View Controller.m (File Owner)
-(UIView *)viewForStepAtIndex:(int)index
{
[[[NSBundle mainBundle]loadNibNamed:#"wizard_newMember" owner:self options:nil] lastObject];;
switch (index) {
case 0:
return self.memberwizard_1;
break;
case 1:
return self.memberwizard_2;
break;
case 2:
return self.memberwizard_3;
break;
case 3:
return self.memberwizard_4;
break;
case 4:
return self.memberwizard_5;
break;
case 5:
return self.memberwizard_6;
break;
case 6:
return self.memberwizard_7;
break;
default:
return self.memberwizard_1;
}
}
Return function of the address book
-(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person
{
[self displayPersonRecord:person];
[self dismissViewControllerAnimated:YES completion:nil];
}
Trying to update the label on the second UIView (this is where the issue occurs - it doesnt work).
-(void) displayPersonRecord:(ABRecordRef)person
{
NSString *firstName = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lastName = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);
NSLog(#"Name is %#", [NSString stringWithFormat:#"%# %#", firstName, lastName]);
self.wizard2_nameLabel.text = [NSString stringWithFormat:#"%# %#", firstName, lastName];
[self.wizardDelegate refresh:self.memberwizard_2]; //if called, the current view will be removed and re-added - then the label gets updated.
}
But as I mentioned if I reload the view then it works (see screenshot)
Reload method IMPORTANT: this is nasty code and not used in production, its just a test to see if a reload of the view helps.
-(void)refresh:(UIView *) oldView
{
[oldView removeFromSuperview];
CGRect frame = self.frame;
frame.origin.x = CGRectGetWidth(frame) * currentIndex;
frame.origin.y = 0;
//UIView *view = [wizardDelegate viewForStepAtIndex:currentIndex];
oldView.frame = frame;
[self addSubview:oldView];
}
If at this point I remove self.memberwizard_2 view from the wizard and add it back in everything works but it doesn't right away. Could that be related to way I initiate the UIViews? By the way the NSLog in the last paragraph works as well showing the name of the contact.
In case anyone knows an easier way to deal with wizards let me know :) PageViewControllers are painful because I need to hand-over one object from screen to screen but need to display different actions in each screen.
Thanks much and apologies for the code mess, I tried to make it as clear as possible but maybe it isn't.
Here's where I think it goes wrong. For each "WizardStep", you call viewForStepAtIndex which loads the NIB and returns the relevant view. You then add that as a subview. But when you process the next WizardStep, the NIB gets loaded again, which creates new instances of all its objects and reconnects all the Outlets and Actions to the newly loaded objects. So the view you have just added as a subview (and so is displayed) is no longer pointed to by your outlets. Thus when you update the label, it is not updating the label on screen, but a completely different label on a view that's not in the hierarchy at all.
So, I would revise your code so that the loadNibNamed: method gets run only once.

All UITableCells disappear when tapping on UITableView in iOS 7

I am having a problem with my UITableView in iOS7. Initially, the data loads in just fine, and I get output in my console that proves that the cells are speaking to the data source correctly, but as soon as I tap anywhere on the table, the cells disappear and the table goes blank. The height of the cells in the empty UITableView seem to be honoring the height my custom prototype cell (410px), but all the data in the cells vanish, and the empty table view acts like it only has one cell in it (like its default state before it gets hooked up to the delegate).
I am using Storyboards for this app.
To get a little context, this app is similar to the iphone Instagram app, and I am using this application as way to learn iOS 7 development. I have been banging my head up against a wall trying to solve this issue, and I can't find any online resources that can help me solve this, so I wanted to ask all the smart peeps on Stack Overflow.
I have prepared a graphic that helps you see the problem
higher resolution version here
Here is my TableViewController code:
#interface PA_PhotoTableViewController ()
#property (nonatomic, copy) NSArray *photos;
#end
#implementation PA_PhotoTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.photos = [[PA_PhotoStore sharedPhotoStore] allPhotos];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[[PA_PhotoStore sharedPhotoStore] allPhotos] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PA_PhotoCell *cell = [tableView dequeueReusableCellWithIdentifier:#"PhotoCell" forIndexPath:indexPath];
PA_Photo *photo = (self.photos)[indexPath.row];
cell.photoTitle.text = photo.title;
cell.photoOwnerName.text = [NSString stringWithFormat:#"%#", photo.owner];
cell.photoLikes.text = #"99";
// Photo Image URL
NSURL *photoImageURL = [NSURL URLWithString:photo.image_full_url];
[cell.photoImage sd_setImageWithURL:photoImageURL placeholderImage:[UIImage imageNamed:#"lightGraySpinningLoader.gif"]];
// Photo Owner Image
[cell.photoOwnerImage sd_setImageWithURL:photoImageURL placeholderImage:[UIImage imageNamed:#"lightGraySpinningLoader.gif"]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// This code never gets called when I try to tap on a cell
NSLog(#"A row was selected");
}
- (void)dealloc {
NSLog(#"dealloc called in PA_PhotoTableViewController");
}
and here is the custom cell code PA_PhotoCell (consolidated .h & .m files):
#interface PA_PhotoCell : UITableViewCell
#property (nonatomic, weak) IBOutlet UIImageView *photoImage;
#property (nonatomic, weak) IBOutlet UILabel *photoTitle;
#property (nonatomic, weak) IBOutlet UILabel *photoOwnerName;
#property (nonatomic, weak) IBOutlet UIImageView *photoOwnerImage;
#property (nonatomic, weak) IBOutlet UILabel *photoLikes;
#property (nonatomic, weak) IBOutlet UILabel *photoTimestamp;
#property (nonatomic, weak) IBOutlet UILabel *photoComments;
#end
#implementation PA_PhotoCell
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
NSLog(#"in set selected");
}
-(void)setHighlighted:(BOOL)highlighted {
NSLog(#"in set highlighted");
}
You can see a few NSLog() calls to help me see if anything is getting called.
Where am I going wrong? The end goal is to click on one of the TableViewCell instances and launch a UINavigationController, I know how to do that, but I can't move on to that step until I figure out why my UITableView won't scroll, and why it disappears when I click on it!
EDIT: After much testing, debugging and experimentation, I have been able to conclude that the problem is actually not with the UITableView at all, and it is, in fact, a problem with how the UITableView is being loaded into its parent view. I still haven't found a solution to my problem, but I am getting closer to finding the cause. Here is what I have discovered:
First, when any of the UIButtons at the bottom of the screen are tapped (see photo reference), it loads the relevant instance of UIViewController into a UIView called placeholderView. When I run my problematic UITableView OUTSIDE of this UIView (where the UITableViewController is acting on its own, not embedded within another UIView) then the table works perfectly, it scrolls, it revives click events, and so on. So as soon as I load the UITableView into the UIView, the UITableView becomes unresponsive (it doesn't scroll or receive tap events) and any attempt to interact with it, the UITableView goes completely blank. My debugging session concludes that the NSArray *photos never gets reset to nil, or manipulated in anyway, the table just goes blank.
So does anyone have any ideas on what would cause a UITableView to do this when being loaded into a generic UIView? All the other views that get loaded into this generic UIView are responsive, and behave as expected. Its just this UITableView that is giving me problems.
If you review the graphic I attached to this post (above), you will see that I am using what appears to be a UITabBarView, but it is, in fact, just a generic view with UIButtons inside. The reason I decided to craft my own "UITabBarView look-alike" instead of using the ready-made UITAbBarView class was because I wanted to give custom functionality to the "menu" button on the bottom left (I want a nice UIView to slide in from the left, and stop about 60 pixels from the right of the screen when the "menu" button is tapped, and I can't figure out how to customize the behavior of the UITabBarView, so I opted for this approach.
Here is the code that is actually loading the UITableViewController into the subview (via a CustomStoryboardSegway):
// PA_HomeViewCustomStoryboardSegue.m
#import "PA_HomeViewCustomStoryboardSegue.h"
#import "PA_HomeViewController.h"
#implementation PA_HomeViewCustomStoryboardSegue
// to create a custom segue, you have to override the perform method
-(void)perform {
// get the source and destination view controllers
PA_HomeViewController *segueSourceController = (PA_HomeViewController *)[self sourceViewController];
UIViewController *destinationController = (UIViewController *)[self destinationViewController];
for (UIView *view in segueSourceController.placeholderView.subviews){
[view removeFromSuperview];
}
segueSourceController.currentViewController = destinationController;
[segueSourceController.placeholderView addSubview:destinationController.view];
}
#end
and here is the header file for my PA_HomeViewController (the view the contains the "placeholderView" which is the target view that loads the various UIViewControllers after the user has tapped the UIButtons at the bottom of the view (similar to a TabBarView) :
#interface PA_HomeViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIView *placeholderView;
#property (weak, nonatomic) UIViewController *currentViewController;
#end
I am hoping that I am just missing something obvious in the way that I am loading the UITableView into the placeholderView, and something in there is causing the UITableView to go completely blank.
When you display the UITableView in a different view, you must always make sure that the view controller which "hosts" the UITableView has a strong reference to its controller. In your case, the data source for the UITableView seems to be deallocated after adding the UITableView as subview.
Changing the currentViewController property from weak to strong should fix your problem.
In swift you need to declare viewcontroller object globally that would result in Strong, in case if you declare locally it results in keep disappearing the cells.
e.g.
var refineViewController : RefineViewController?
then you can access that controller using below code that would not result in disappearing cells.
func showRefineView(isFindHomeTab isFindHomeTab : Bool){
refineViewController = RefineViewController(nibName: String(BaseGroupedTableVC),bundle : nil)
refineViewController!.refineSearchDelegate = self
refineViewController!.view.frame = CGRectMake(0, -490, self.view.frame.size.width, self.view.frame.size.height)
UIView.animateWithDuration(0.3, delay: 0.0, options: .CurveEaseOut, animations:
{
self.refineViewController!.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)
self.refineViewController!.isFindHomeTab = isFindHomeTab
}, completion: nil)
self.view.addSubview(refineViewController!.view)
}
I experienced the exact same problem. The issue was that I was using a custom datasource class (called tableVCDataSource), and was setting the tableView's dataSource incorrectly in the ViewController class. I was doing:
override func viewDidLoad() {
mainTableView.dataSource = TableVCDataSource()
}
when I should have been doing:
fileprivate var tableVCDataSource: TableVCDataSource?
override func viewDidLoad() {
tableVCDataSource = TableVCDataSource()
mainTableView.dataSource = tableVCDataSource
}
This solved my issue.

Memory is not released under ARC

I have an app with a parent View Controller. It has some buttons and when one of them is clicked it presents a Modal View Controller (using XIB). The code I use to present and dismiss the Modal VC is :
iPadViewController *iPadVC = [[iPadViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:iPadVC animated:YES completion:NULL];
and to dismiss :
-(IBAction)Back:(id)sender{
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
So the problem is, when I dismiss it, it does not release any memory. And if I present it 3/4 times it crashes. I am using ARC, never had similar problems because I tough that ARC did all the memory management job.
I do have some backgrounds that need a lot of space and they are not getting released either. I tried :
[backgroundImage removeFromSuperview];
backgroundImage=nil;
The memory does decrease using this code, I'm not sure if the image was released because the next time I press the button the memory increases to almost 300mb and terminates due to "memory pressure". If the VC was released it would work fine because it only uses 160mb on the iPad and 65mb on the iPhone. Also, My image is selected through the Xib utilities :
And I tried to use Xcode instruments and it does not show any leak (!) but it does show that the allocations are growing and growing every time I click a button.
and on my ViewController.h:
IBOutlet UIImageView (...);
IBOutlet UIImageView (...);
IBOutlet UILabel (...);
IBOutlet UIButton (...);
IBOutlet NSTimer (...);
IBOutlet UIImage (...);
IBOutlet UIView (...);
-(IBAction)Back:(id)sender;
#property (nonatomic, assign) int ;
#property (nonatomic) IBOutlet UIButton ;
#property (nonatomic) IBOutlet UIButton ;
#property (nonatomic) IBOutlet UIButton ;
#property (nonatomic) IBOutlet UIView ;
#property (nonatomic) IBOutlet UILabel ;
I tried to give all the details about my code, but if you need anything else just let me know, and thank you all so much!
If Your images are big please see this question: Problem dealloc'ing memory used by UIImageViews with fairly large image in an UIScrollView
To sum up: when using nib files all the assigned images are loaded using
[UIImage imageNamed]
method which is known to cause huge memory allocations because it always caches the images.
Try assigning the images to views in the code with
[UIImage imageWithContentsOfFile:path];
method (it is described in the answer to above question).
In the modal view controller:
[self dismissViewControllerAnimated:TRUE completion:Nil];
In the main View controller check it exists first before presenting it:
iPadViewController *iPadVC;
if (iPadVC == Nil)
iPadVC = [[iPadViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:iPadVC animated:YES completion:NULL];
Sounds like iPadVC is always in scope so ARC may not be releasing it.

Why is my IBOutlet being released under ARC?

The Problem
An IBOutlet is released before I have a chance to use it.
What I Want
I want to access a navigation controller from my app delegate so I can reload a table view.
My Setup
I have:
A Main.xib that's set as my main interface in target settings
An IBOutlet to the navigation controller as an ivar on my app delegate
This IBOutlet hooked up to the correct navigation controller in Main.xib
App Delegate is instantiated in the xib but not set as File's Owner
I'm using ARC, Xcode 4.3.2 and iOS5.1
What I've Tried
Changing deployment target
Putting a break point on dealloc for the navigation controller, app delegate - they're never called
Reading everything I can find on ARC and IBOutlets - nothing seems to contradict what I'm doing
Creating a fresh project with just a the minimum classes required - I see exactly the same problem
Code
KPAppDelegate.h
#interface KPAppDelegate : UIResponder <UIApplicationDelegate> {
IBOutlet KPBrowseExpensesNavigationController *nc;
}
#property (strong) IBOutlet KPBrowseExpensesNavigationController *nc;
KPAppDelegate.m
#implementation KPAppDelegate
#synthesize nc;
-(void)setNc:(KPBrowseExpensesNavigationController *)nc_ {
nc = nc_; // This gets called on view load and nc gets set.
}
...snip...
// This is called about 5 seconds after app startup
-(void)objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)objects {
// By the time we get here, nc is nil.
UITableViewController *tvc = [[nc viewControllers] objectAtIndex:0];
[[tvc tableView] reloadData];
}
#end
UPDATE
I must be doing something really silly here. Even an incredibly simple project still shows this problem. See link below.
Download a simple test project that shows the problem.
In Window nib, set the FilesOwner Class as UIApplication and then point it's delegate from Outlets to the AppDelegate object. This is what is wrong in your project example.
is your outlet from the Interface Builder set as an KPBrowseExpensesNavigationController type?
If not it is not going to create the connection between your nib and ViewController.
You should set its Custom Class as KPBrowseExpensesNavigationController in the Identity Inspector
I am not sure why you declare it as a property & a non-property. I should do something like this:
#interface KPAppDelegate : UIResponder <UIApplicationDelegate>
#property (nonatomic, strong) IBOutlet KPBrowseExpensesNavigationController *nc;
And in your implementation:
#implementation KPAppDelegate
#synthesize nc = _nc; // So you don't accidentally use nc
...snip...
// This is called about 5 seconds after app startup
-(void)objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)objects {
// By the time we get here, nc is nil.
UITableViewController *tvc = [[**self.nc** viewControllers] objectAtIndex:0];
[[tvc tableView] reloadData];
}
#end
Hope this helps!
I didn't see where you alloc your nav controller. Just declaring the property won't assign any value to it, so it would be nil. In you -didFinishLaunchingWithOptions in the app delegate, set your alloc/init statement. Everything else looks fine.
KPBrowseExpensesNavigationController *nc = [[KPBrowseExpensesNavigationController alloc] init];
If you have a custom init, you can use that too, but just make sure to set it up before you try and use it.

Resources