Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dfletcher

macrumors newbie
Original poster
Mar 3, 2010
4
0
Hi,
I am new to the iPhone SDK, however, I have been programming for a number of years. My experience ranges from Perl to Visual basic to JavaScript to SQL. I programmed briefly in C in college (a while ago) I find objective-C a very cool language and I am excited learning it. I think my main confusion is with IB.

I am creating a fitness related app that has 6 UITableViews that, in part, allow the user to drill down to choose exercises they want and they can then record the number of sets of reps they did and keep track of their progress.

I have successfully created the table views and they work fine. What is really hanging me up (I don't know why, I suspect it's IB) I want to have a Menu view load first. The menu will have buttons that when clicked will load the respective table views. For some reason I can't seem to get my head around how to make this happen. I finally got the menu view to load and hooked up one of the buttons but I can't seem to get it to work.

I have tried to use:
Code:
 CardioRootViewController *cardioRVC = [[CardioRootViewController alloc] initWithNibName:@"CardioRootViewController" bundle:[NSBundle mainBundle]];
	[self.navigationController pushViewController:cardioRVC animated:YES];
	[cardioRVC release]; 

and

CardioRootViewController *cardioRVC = [[CardioRootViewController alloc] initWithNibName:@"CardioRootViewController" bundle:nil];
	[self presentModalViewController:cardioRVC animated:YES];
[cardioRVC release];
	
	
and	
	
	CardioRootViewController *RootVC = [[CardioRootViewController alloc] initWithNibName:nil bundle:nil];
	[self presentModalViewController:RootVC animated:YES];
[RootVC release];

where CardioRootViewController is the nib name of 1 of the table views.

The simulator tries to load but hangs.

every one of these get me "Terminating app due to uncaught exception."
Code:
'NSInvalidArgumentException', reason: '*** -[UIView cardioButtonPressed]: unrecognized selector sent to instance 0x4523cc0'
2010-03-03 17:40:03.200 DrillDownApp[6078:20b] Stack:

I may not be connecting up correctly in IB, but the truth is I am stumped.
Can anyone out there she a bit of light on this? It sure would help my frustration level.

I just finished re-reading Navigation Controllers in the docs, I also have and read, "Sam's teach yourself iPhone App development" Ray & Johnson, "Beginning iPhone Development" Mark & LaMarche, "iPhone In Action" Allen & Appelcline, and I am using "Programming in Objective-C 2.0" Kochan, as a reference. Als I have lurked and searched here to find an answer. So I really have tried to solve this on my own first.

Please excuse the long post.

Thanks very much in advance
Dave Fletcher
 
A simple thing really, but I wouldn't use 'CardioRootViewController' for the nib name, if I were you. This could lead to a bit of confusion at some point and make it a bit more difficult to keep track of things. I would simplify the nib name to 'CardioView'. I know it shows up in red in the code view, but all the same.

I assume this is going in a view controller .m?

Not sure if the following might help as an alternative example.

Code:
DetailViewController *viewController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];

		self.detailView = viewController;
		[viewController release];
	}
	
	// Set the title of the view to the detail's name
	self.detailView.title = [detail name];

	// Push in the view controller last of all so updates are not visible
	[self.navigationController pushViewController:self.detailView animated:YES];
 
The runtime exception sugggests that you've hooked up your action incorrectly in IB. I assume that cardioButtonPressed is the name of your action method that is called when you tap a button. The target of an action like that is usually a view controller. It looks like you've connected it to a view instead.

Go into IB and set your nib window to display in list mode. Then control-click on each of the lines in the window. You should see a little black window that displays the connections for the object you've clicked on. Use this to determine that all of your connections are correct.
 
Thank You for the reply,

Actually, I'm not even sure what I should have in my MainWindow.xib.
I have tried so many different combinations I'm very confused.

Ok,
I have 5 table view controllers all of which use a .h, .m, AppDelegate.h
and AppDelegate.m files. the delegate files help to load the data from respective .plist files to store the drill down menus.
I know these names will end up biting me in the end, but they sort of evolved.
RootViewController
CardioRootViewController
CoreViewController
YogaViewController
StretchingViewController

MainWindow (will hopefully load 1st) loads the view with the menu to set up the navigation
you are correct boyplunder, in the MainWindow.m is where I place my IBActions to connect the buttions to load the respective tableviews.

If I place an NSObject in the MainWindow nib and set it's class to say... CardioAppDelegate Then Connect the File's owner delegate to CardioAppDelegate. Then CardioAppDelegate's navigationController to the navigation controller for CardioRootViewController. CardioRootViewController class CardioRootViewController. Then it will display the Cardio TableView. If I substitute another RootViewController, the the same procedure. It will load the correct TableView.
I can't seem to figure out how to insert an image.
(I am obviously new to this forum) To show what I have in the nib.
So here it is:

File's Owner
App Delegate
Window
4 Navigation Controllers (1 for each ViewController)
1 View (Containing the button menu)

So please what am I doing wrong?

Thanks again for your help.
Dave
 
Let's go back to the actual question you posed: Adding a menu to start with.

MainWindow.xib always loads first and most apps will load the RootViewController to show the initial list. [I think I am right in saying that the MainWindow has to be first. I've always worked with it in the apps I have worked on.] This is certainly true of most reference or data apps, mine included. So, what you need to do, I suspect, is set up a MenuViewController that starts the app instead of the RootViewController, which is probably the start at the moment. The MenuViewController then links to the RootViewController with a button and a transition.

Adding an image can be programmed

Code:
UIImage *backgroundImage = [UIImage imageNamed:@"Background.png"];
  [[self view] setBackgroundColor:[UIColor colorWithPatternImage:backgroundImage]];

or added using an Image view in IB that's at the back of everything else. [Assign the image by selecting it in the attributes pane. The image needs to be in the resources and assigned to the app.]
 
OK,
This sounds like I'm getting on track. Thanks again for the help.

I created a MenuViewController, with .h, .m, .xib files. I placed my menu in the MenuViewController.xib. I set up my IBAction in the .h and .m files and connected it to the button. The problem now is I can't for the life of me get the the thing to load from MainWindow.xib. Is there some code I am missing to set this up or am I just not hooking it up correctly in IB?

Thanks;
Dave
 
Just for example, get Xcode to create a starting Nav controller project.

Look at the way the MainWindow uses the RootViewController. All you really need to do is replace the RootViewController on the MainWindow with the MenuViewController instead. This should load the menu by default, and then you link the RootViewController from the Menu view. You're slotting in a new view in between the two.
 
Thanks so much for the great suggestion.
I have successfully gotten the menu to load from MenuViewController.xib.
I have hooked up my two IBAction StrengthSwitchPage and CardiohSwitchPage functions to the appropriate buttons but I am now again receiving:


2010-03-06 09:56:19.361 DrillDownApp[4950:20b] *** -[MenuViewController StrengthSwitchPage:]: unrecognized selector sent to instance 0x4527d60
2010-03-06 09:56:19.362 DrillDownApp[4950:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[MenuViewController StrengthSwitchPage:]: unrecognized selector sent to instance 0x4527d60'
2010-03-06 09:56:19.363 DrillDownApp[4950:20b] Stack: (
9143387,
2499907131,
9525307,
9094774,
8947394,
23589977,
23997346,
24006083,
24001295,
23694899,
23603228,
23630005,
917201,
8928128,
8924232,
911245,
911442,
23633923,
10860,
10714
)


I have tried several different configurations

Code:
-(IBAction)StrengthSwitchPage:(id)sender {
        RootViewController *strengthRVC = [[RootViewController alloc] initWithNibName:nil bundle:nil];
        [self presentModalViewController:strengthRVC animated:YES];
        [strengthRVC release];
}
and 
-(IBAction)StrengthSwitchPage:(id)sender {
        RootViewController *strengthRVC = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
	[self.navigationController pushViewController:strengthRVC animated:YES];
	[strengthRVC release];
}

I tried to use the method you suggested earlier but I guess I don't exactly understand the code
Code:
DetailViewController *viewController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];

		self.detailView = viewController;
		[viewController release];
	}
	
	// Set the title of the view to the detail's name
	self.detailView.title = [detail name];

	// Push in the view controller last of all so updates are not visible
	[self.navigationController pushViewController:self.detailView animated:YES];

I tried to write it like this:

Code:
-(IBAction)StrengthSwitchPage:(id)sender {

        RootViewController *viewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
	self.viewController = viewController;
	[viewController release];
	}

       // Set the title of the view to the detail's name
	self.detailView.title = [Strength];

	// Push in the view controller last of all so updates are not visible
	[self.navigationController pushViewController:self.detailView animated:YES];
I received several errors.

Anyway, it doesn't seem to matter what code I put in there, I still get the same error.
Which tells me something that maybe else is wrong.

Any idea what I need to do in the MenuViewController.xib? Here is where I am trying to load UITableViews.

You have really helped me a lot.
Thanks Again for your time and effort.

Dave
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.