Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-28-2008, 07:28 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 44
Default UINavigationController subclassing

So I have a bit of a problem. I’m going to use the clock app as an example for my problem.

When I want to add a new alarm, I create a blank alarm object with some default values. However, I need to be able to use different nibs for input/selection.

I originally loaded all of the nibs and accessed their values from the main "add view" directly. However, this is too memory-intensive for my application. So, I subclassed UINavigationController so that it could store the new alarm object, and as the input/selection nibs came and went, they could update the new alarm object by saying self.navigationController.newAlarmObject.time = @"Time";.

This, however, isn’t working. If anyone has suggestions as to how I can make this work, or other ways to achieve what I’m trying to do, it’d be much appreciated.
rendezvouscp is offline   Reply With Quote
Old 10-28-2008, 09:45 PM   #2 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 361
Default

I am unsure how to set up the app, but just letting you know that UINavigationController should never be subclassed.
DevTeamOfOne is offline   Reply With Quote
Old 10-29-2008, 10:42 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 44
Default

Quote:
Originally Posted by DevTeamOfOne View Post
I am unsure how to set up the app, but just letting you know that UINavigationController should never be subclassed.
I’m interested why you say that. I haven’t read in the docs or header files anything that says never to do it. Or, maybe people shouldn’t do it for the very issue I’m running into!

So, I’m currently trying a different pattern to solve the issue, which includes loading the nibs when needed and deallocating all of them (that aren’t nil) whenever the main "add view" appears.
rendezvouscp is offline   Reply With Quote
Old 10-29-2008, 11:02 AM   #4 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 361
Default

It is stated in the ViewController programming guide that TabBarControllers and NavigationControllers "Don't need to be subclassed" and Apple never say that about any class. What are they saying? You shouldn't. It creates mega hassles.
DevTeamOfOne is offline   Reply With Quote
Old 10-29-2008, 11:41 AM   #5 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 298
Default

Create a new NavigationController with the AddAlarmViewController as the root view controller and present it as a ModalViewController from your main NavigationController. This way you wouldnt have to worry about subclassing NavigationController. Your add alarm view controller will hold the new blank alarm object.

I agree with the DevTeamOne, that UINavigationController should never be subclasses.
javid.alimohideen is offline   Reply With Quote
Old 10-29-2008, 12:00 PM   #6 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 44
Default

Hi javid.alimohideen,

My problem lies with accessing the data from my new alarm object in all of the subsequent views. Choosing repeat, sound, and label all happen in a different view, and those views need to update the new alarm object in the AddAlarmViewController. I chose to subclass the navigation controller because that is common among all of the view controllers, but I’m going to try the method I outlined above instead.

I’ll let everyone know how it goes!
rendezvouscp is offline   Reply With Quote
Old 10-29-2008, 12:05 PM   #7 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 361
Default

I recommend a simpler way: Do all your organization in the app delegate and create a singleton object version of it in each subclass. Then apply that to each level in your navigation controller sequentially.

So, you make an alteration. Send that data to the app delegate by sending the app delegate a message with the information required. That custom message sends it off to the root view controller. That root viewcontroller sets the property of the next one and so on.
DevTeamOfOne is offline   Reply With Quote
Old 10-29-2008, 12:10 PM   #8 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 298
Default

Ok. In that case, why don't you sublcass the Views or view controllers where you are changing the properties.
For example, say you have view AlarmRepeatViewController.xib and AlarmRepeatViewController.
You would doing something like initWithNibName:@"AlarmRepeatViewController"

In your AlarmRepeatViewController.h file, create a property of type Alarm

Code:
AlarmRepeatViewController.h
@interface
  Alarm *alarm;
@property (nonatomic, retain) Alarm *alarm;
 @end

// Before you push the AlarmRepeatViewController set the alarm object value

AlarmRepeatViewController *controller = [[AlarmRepeatViewController alloc] initWithNibName:@"AlarmRepeatViewController" bundle: nil];

controller.alarm = self.myAlarmObject
[self.navigationController pushViewController: controller animated:YES];
[controller release];
javid.alimohideen is offline   Reply With Quote
Old 10-29-2008, 12:37 PM   #9 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 361
Default

This is generally the idea I speak of. Its simple and effective, and not a waste of time like subclassing UINavigationController.

This is, tbh, basic stuff.

I would recommend, however, instead of the way you do it above, encase that in a method and send the app delegate a message to change the main property which sends the root view controller a message automatically to resyncronise its data to the app delegate which then asks the next view to syncronise down and so on.

Make sense?
DevTeamOfOne is offline   Reply With Quote
Old 11-12-2008, 11:14 AM   #10 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 44
Default

I didn’t find any of the above methods to be particularly useful. For reference, here’s the solution I came up with.

Each of the detail views (repeat, label, etc.) send a message (thanks to NSObject’s performSelector:withObject: method) to the main "add" view controller when they are about to disappear with new data that they have. The message in the "add" view controller then updates its blank alarm object and updates the appropriate row (instead of reloading the entire table).
rendezvouscp is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,145
Threads: 38,923
Posts: 170,776
Top Poster: smasher (2,565)
Welcome to our newest member, user314159
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:37 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0