Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 2, 2011, 05:48 AM   #1
dantastic
macrumors 6502
 
Join Date: Jan 2011
IB linking question - controller to view

Hello again,

This is a pretty fundamental question and I don't get how it works.

I have been coding away at individual chunks of an app and I've come to the point where I need to pull stuff together and I've run in to a wall here. I realize I may have been doing this completely wrong to this point.....

My base app consist of a main view with an info button. hit the info button and we flip over to a new view with a navigation controller on top that has 2 buttons. - simple.

I also have a UITableViewController where all the cool stuff is happening. I want to put the UITableView of this UITableViewController into what is left of the UIView below the navigation bar.

I have added the controller to the nib but how do I get the 'table view' under 'Settings Table View' to sit on my view?

I have tried to add a new table view to the view and linked up the delegate & dataSource. (screenie 2). This is not working and is crashing but without any messages. I imagine that the TableViewController is not initialized.

I've kindof hit the wall here. How do I do this?
Back to basics as well, have I been doing this right or should I have approached this completely different?
Attached Thumbnails
Click image for larger version

Name:	flipview.png
Views:	60
Size:	49.2 KB
ID:	269714   Click image for larger version

Name:	scr2.png
Views:	40
Size:	69.5 KB
ID:	269716  
dantastic is offline   0 Reply With Quote
Old Feb 2, 2011, 07:09 AM   #2
dantastic
Thread Starter
macrumors 6502
 
Join Date: Jan 2011
I have once again had more luck abandoning IB.

I have removed all references I did and reverted to screenie 1 in the first post.

Then in the controller where I have the view I want to add my controller to I have done this:

Code:
	SettingsTableView *settingsView = [[SettingsTableView alloc] initWithNibName:@"SettingsTableView" bundle:nil];
	
	[self.view addSubview:[settingsView view]];
And the view loads - but it loads on top of the navigation bar so that's no good. I guess my first question stands.
dantastic is offline   0 Reply With Quote
Old Feb 2, 2011, 11:58 AM   #3
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
I'd probably favor a non-IB approach for this as well. It's probably just a matter of setting the frame, especially the origin, for the table view correctly. (Exercise left to the reader: set the autoresizing mask appropriately as well. )

But I would make sure you are instantiating a table view controller instead of just a table view. Something like:
Code:
	SettingsTableViewController *settings = [[SettingsTableViewController alloc] init];
	self.settingsTableViewController = settings;
	settings.view.frame = CGRectMake(x, y, width, height);
	[self.view addSubview:settings.view];
	[settings release];
__________________
dejo is online now   0 Reply With Quote
Old Feb 2, 2011, 11:58 AM   #4
PhoneyDeveloper
macrumors 68020
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
The navigation controller has a root view controller. I recommend that you build the Navigation-based application template and see how things are hooked up in that app. Do it the same way.
PhoneyDeveloper is offline   0 Reply With Quote
Old Feb 2, 2011, 01:37 PM   #5
dantastic
Thread Starter
macrumors 6502
 
Join Date: Jan 2011
Quote:
Originally Posted by dejo View Post
I'd probably favor a non-IB approach for this as well. It's probably just a matter of setting the frame, especially the origin, for the table view correctly. (Exercise left to the reader: set the autoresizing mask appropriately as well. )

But I would make sure you are instantiating a table view controller instead of just a table view. Something like:
Code:
	SettingsTableViewController *settings = [[SettingsTableViewController alloc] init];
	self.settingsTableViewController = settings;
	settings.view.frame = CGRectMake(x, y, width, height);
	[self.view addSubview:settings.view];
	[settings release];

That is pretty much spot on what I ended up doing.

I'm brand new to objective-c and the interface builder in particular. Is it common that there are tasks the IB simply can't do? What can be done in the IB gets done real quick so it's a massive time saver when you can use it.

I suppose, should I spend more effort trying to learn IB or are there things like this task that are just better suited to do programmatically?
dantastic is offline   0 Reply With Quote
Old Feb 2, 2011, 02:13 PM   #6
PhoneyDeveloper
macrumors 68020
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
Code like this is almost never correct:

Code:
[self.view addSubview:someviewcontroller.view];
There are three container view controllers provided by Apple , UINavigationController, UITabBarController, UISplitViewController. It is not recommended to have more than one view controller that is controlling part of the screen at any one time (except for UISplitViewController, which is designed to have two at a time).

Use Apple's container view controllers in the way they were intended to be used and things will just work. Don't, and you'll likely have problems. The problems are usually related to rotation of the device.

The example mentioned in this thread should work just fine in IB if the view controller hierarchy is set up the way the navbar app template does it.
PhoneyDeveloper is offline   0 Reply With Quote
Old Feb 2, 2011, 04:29 PM   #7
dantastic
Thread Starter
macrumors 6502
 
Join Date: Jan 2011
Right, so I am doing it wrong. I was expecting as much.

I will digest for a bit and get back with followup questions. Thanks!
dantastic is offline   0 Reply With Quote
Old Feb 3, 2011, 08:12 AM   #8
dantastic
Thread Starter
macrumors 6502
 
Join Date: Jan 2011
Ok, take 2 at this. Using a "utility application" template in xcode.

Main view, no problem. Touch the info button and the second view is loaded.

The template provide you with a UIView with a UINavigationBar. The controller created extends UIViewController.

I have copy/pasted all my code from my old controller that was extending UITableViewController into the new one created that extends UIViewController.

The tableView holds cells with a bunch of buttons each and in order to figure out which cell and button the request came from I've the following and it's somewhat broken in the new controller:

Code:
	
- (IBAction)buttonPressed:(id)sender event:(id) event{
	UIButton *button = (UIButton *)sender;
	NSSet *touches = [event allTouches];
	UITouch *touch = [touches anyObject];
*	CGPoint currentTouchPosition = [touch locationInView:self.tableView];
*	NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
	if (indexPath != nil) {
		....

*	"Request for member 'tableView' in something not a structure or union"
So for this to work I need to be able to be able to call the tableView within the view itself. Something like self.view.tableview - is this correct approach? If it is, how do I do it?

Or if this is wrong, how do I figure out which button in which cell was pressed?
dantastic is offline   0 Reply With Quote
Old Feb 3, 2011, 08:31 AM   #9
dantastic
Thread Starter
macrumors 6502
 
Join Date: Jan 2011
Hey Phoney,

while trying to figure this one out I came across an old post of yours: http://forums.macrumors.com/showthread.php?t=577677

After setting and linking in IB an outlet for a 'tableView' property the above code works!

thanks!
dantastic is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
More IB linking questions, buttons in custom cells? dantastic iPhone/iPad Programming 0 Feb 4, 2011 09:04 AM
Win7 HTPC on network - Can't figure it out - how to view existing itunes videos? Sean Dempsey Apple TV and Home Theater 5 Oct 10, 2010 11:39 AM
Networking question - how to control the acess when using Apple Airport Extreme? sphuyal MacBook 4 Aug 18, 2010 04:03 PM
Passing values from View Controller to View sm4ck iPhone/iPad Programming 3 Dec 22, 2009 08:36 AM
linking keyboard volume control to app volume controls iansilv OS X 3 Dec 15, 2008 10:57 PM


All times are GMT -5. The time now is 02:30 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC