Jump to content

iPhone SDK - Interface Builder Tutorial


115 posts in this topic

Recommended Posts

PascalW, that works, but only if the only thing in the string is a float, which isn't always the case. NSScanners will scan the whole string picking up any floats.

 

True, but as I read in this case it would be appropriate to use this convention.

Link to comment
Share on other sites

Any able to change the attibutes of a button or text field using Interface Builder(IB)? . IB is not responding to whatever i set like changing the background color of the button or textfield and etc. Is this an issue or something that i am missing here.

But with the same IB i can do all these setting properly for a MAC OS window / button / text field.

Link to comment
Share on other sites

Try doing [tableView reloadData];

 

I am doing that in "viewWillAppear". I actually NSLog the cell text, and the logged text is the right one, just the one displayed is wrong. Also, when I go back to my table view after a Disclosure View, my selection remains selected. So I guess that the table is not "repainted". I tried using the redraw context property, no dice.

 

Anyone have a DrillDownApp where the GUI (and tableviews) are created with IB ?

 

Thanks,

M.

 

PS: anyone tried changing a button type from RoundRect to, let's say, a DONE button ? I get a compile error for any button except RoundRect.

Link to comment
Share on other sites

DaveGee, you would do something like cell.accessoryView = (accessory view to use) and cell.accessoryAction = @selector(action:). You should implement these in your table's data source, so you can set them based on the cell index.

 

 

Okay I did that and it works... but... here's the new wrinkle...

 

As part of TableView we have a default method of:

 

"- (void)tableView:(UITableView *)tableView accessoryButtonClickedForRowWithIndexPath:(NSIndexPath *)indexPath"

 

(but I can't seem to get it to trigger - so I used the solution you suggested)

 

In the solution you presented I have the (two) following lines:

 

cell.accessoryAction = @selector(myCustomAction); // Including a : at the end didn't work!!

cell.target = self;

 

{SNIP the rest of my babbling}

 

======================================================================

***EDIT***

 

Okay I finally got things going CORRECTLY and to the best of my knowledge the way they should be...

 

Here was my initial downfall:

 

"- (void)tableView:(UITableView *)tableView accessoryButtonClickedForRowWithIndexPath:(NSIndexPath *)indexPath"

 

I was using this method --- well because I found it somewhere --- I know I didn't make it up... :) (maybe it was changed from the initial SDK??) I dunno but that is the method that I thought I needed to implement.

 

***WRONG***

 

Simply reading the headers for UITableView I instead I saw this method referneced:

 

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath

 

I took out the overrides I was trying get working (in otherwords I deleted these new lines that I was speaking about above)

 

cell.accessoryAction = @selector(myCustomAction); // Including a : at the end didn't work!!

cell.target = self;

 

Then I renamed accessoryButtonClickedForRowWithIndexPath to accessoryButtonTappedForRowWithIndexPath...

 

Compiled and all is now good with my world (for a little while anyway) :lol:

 

Thanks again for everyones help.

 

Dave

Link to comment
Share on other sites

Compiled and all is now good with my world (for a little while anyway) :(

 

Thanks again for everyones help.

 

Dave

 

Yes that was the thing :-) I had to look for myself and I implemented in one example ... here it is :-)

 

Recipes.zip

 

 

By the way ... DID ANYONE DID A TABLEVIEW FROM IB ?! Am I the only one that cannot use a tableview from IB ?

(In my example I reinitialize the tableviews in my code to make them work...)

 

Cheers,

M.

Link to comment
Share on other sites

Compiled and all is now good with my world (for a little while anyway) :(

 

Any chance you could post/upload your working example? As you are aware there is not much out there and any examples would be appreciated.

 

Thanks

 

Greg

Link to comment
Share on other sites

By the way ... DID ANYONE DID A TABLEVIEW FROM IB ?! Am I the only one that cannot use a tableview from IB ? (In my example I reinitialize the tableviews in my code to make them work...)
I've been doing all my tables 'the old fashion way' :( -- I've yet to really get into IB.Since I was reading so many people having problems of one sort or another... I figure I'd wait till the painful getting up to speed process is over... from your post I can see that it's clearly not..
Any chance you could post/upload your working example? As you are aware there is not much out there and any examples would be appreciated.ThanksGreg
Look at the post right above yours... mmk has posted a great working example.Dave
Link to comment
Share on other sites

When I do the sample, for MainWindow, all that i see generated is a IB document when it gets added to the XCode project.

What does IBs Write class files do? does it write the files and add them to the XCode project as well?

doesn't seem to be working..

any input will help

thanks

Link to comment
Share on other sites

In order to have XCode & IB working together, I recommend you to use the template joined (made by laurris from http://www.objective-cocoa.org)

 

Apple forgot to add a XIB entry into the Cocoa Touch Application template.

 

Just paste the folder into /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application/

 

Have fun ^_^

Cocoa_Touch_Application__Xib_.zip

Link to comment
Share on other sites

Hi,

Has anyone tried to figure out how to use the Navigation Controller and Navigation Item in the IB? Here is what i did:

1. Create a View Controller (MainViewController)

2. Added a Navigation Item to by dragging it from toolbox. Configured navigation item properties, like title, prompt, customLeftView and CustomRightView

3. Added a view, and dragged few buttons and labels into it.

 

In Xcode,

 MainViewControllers *mvc = [[[MainViewController alloc] init] autorelease];
UINavigationCOntroller *nac = [[UINavigationController alloc] initWithRootViewController: mac];

  [window addSubView: nac view];
  [window makeKeyAndVisible];

 

When i build and run, I just see view and i don't see the navigation item with custom Left and Right View.

 

Can someone share some examples and thoughts on how to use these controllers using IB?

 

Any help would be great.

 

Thanks,

Javid

Link to comment
Share on other sites

In order to have XCode & IB working together, I recommend you to use the template joined (made by laurris from http://www.objective-cocoa.org)Apple forgot to add a XIB entry into the Cocoa Touch Application template.Just paste the folder into /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application/Have fun :P
Thanks exd.. i am not sure what to paste into the folder.. the project you zipped.. does it contain the template?what do i paste into the above folder?also, the website is in french.. :(can you provide a link to the template download?THANKS!turin
Thanks exd.. i am not sure what to paste into the folder.. the project you zipped.. does it contain the template?what do i paste into the above folder?also, the website is in french.. :rolleyes: can you provide a link to the template download?THANKS!turin
oops .. nm.. found the entry in the project..putting the whole folder there..THANKS
In order to have XCode & IB working together, I recommend you to use the template joined (made by laurris from http://www.objective-cocoa.org)Apple forgot to add a XIB entry into the Cocoa Touch Application template.Just paste the folder into /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application/Have fun :)
I used the template and have a couple of questions. When i create the XIB (MainWindow) and added to the XIB Cocoa Touch aplication (empty) that I createdall i see is the MainWindow.xib file. I double click it and I could modify the Interface (add stuff to it)but when I run it I don't see anything but a black screen... (maybe not rendering it correctly or setting up correctly in IB)also, in IB i say to write the class files and adds them to the xcode project.. i get a couple of errors..Cocoa/Cocoa.h (no such file or directory)andduplicate interface definition for UIWindow...if one wants to write class files to modify it and not rely on the XIB file is there an¥ way to use both at the same time?Thanks
Link to comment
Share on other sites

Does anyone have a simple walkthrough/explanation on getting a button wired up in IB using laurris' template? I can get thing wired up loading the nib manually but cant seem to get it going without crashing using Laurris' template.

Link to comment
Share on other sites

Any idea how to draw a level indicator(bar)on a window?...I am not able to find any classes related to that . In MAC OS sdk there is NSLevelIndicator. Is it included anywhere in the UIKit.?

Link to comment
Share on other sites

Hmm... What am I doing wrong?

 

I'm trying to follow the tutorial in the first post:

  1. Create a new Cocoa Touch project in Xcode. DONE!
  2. You should be presented with the main window, you can ignore this for now. Open Interface Builder. CAN'T FIND IT!

I have been trying to find the Interface Builder for some hours now but it isn't there!! Can anyone just give me a direction exactly how to open the Interface Builder??

 

I'm quite sure that I'm using the latest SDK (iphone_sdk_9a2151.dmg). On apple.com I just clicked:

"A New Version of the iPhone SDK is Now Available Now includes Interface Builder."

 

Why can't I find the Interface builder?

 

Please help!

Link to comment
Share on other sites

Hmm... What am I doing wrong?

 

I'm trying to follow the tutorial in the first post:

  1. Create a new Cocoa Touch project in Xcode. DONE!
  2. You should be presented with the main window, you can ignore this for now. Open Interface Builder. CAN'T FIND IT!

I have been trying to find the Interface Builder for some hours now but it isn't there!! Can anyone just give me a direction exactly how to open the Interface Builder??

 

I'm quite sure that I'm using the latest SDK (iphone_sdk_9a2151.dmg). On apple.com I just clicked:

"A New Version of the iPhone SDK is Now Available Now includes Interface Builder."

 

Why can't I find the Interface builder?

 

Please help!

In spotlight, right top hand corner of your desktop, search for Interface builder, hopefully, if you have latest SDK installed it should show up

Link to comment
Share on other sites

Thanks for these examples. I've gone through both of them and got both working.

now, im trying to integrate one of my touch event tests, trying to figure out how to handle touch events, then passing them onto buttons.

 

Quick question. With the new version of the sdk, im not able to see NSLog prints in the console. They still work when I do a cocoa app, but not a cocoa touch app. Anyone else notice this? seems like a pretty basic thing, but im sure it could be user error.

Link to comment
Share on other sites

From the second Beta version,NSLog got messed up. Instead of printing it on the xcode console, the NSLog statements are getting printed on the system log in the Console App ( u can find this application in Application ->utilities ->Console). u can some post earlier related to the same issue.From the second Beta version,NSLog got messed up. Instead of printing it on the xcode console, the NSLog statements are getting printed on the system log in the Console App ( u can find this application in Application ->utilities ->Console). u can some post earlier related to the same issue.

Link to comment
Share on other sites

May be off topic, but has anyone had any luck signing their code? After installing the certificates from the beta program and setting the project up to use them, building for the device runs a code signing build phase which always returns the error:

 

object file format invalid or unsuitable

 

 

Oh, and back on topic, anyone got Tabbars working in IB? They don't seem to appear unless I recreate them programmatically in my code. I checked the frame of the Tabbar I inserted into my nib, and during runtime, it's always 0 width, 0 height, although resetting the frame/bounds is still not enough to get the Tabbar to appear...I need to manually alloc/init it, and add it as a subview of my main window before I see it.

Link to comment
Share on other sites

Oh, and back on topic, anyone got Tabbars working in IB? They don't seem to appear unless I recreate them programmatically in my code. I checked the frame of the Tabbar I inserted into my nib, and during runtime, it's always 0 width, 0 height, although resetting the frame/bounds is still not enough to get the Tabbar to appear...I need to manually alloc/init it, and add it as a subview of my main window before I see it.
Haven't tried yet.... but i guess this is just like the other cases:NavigationController - have to programatically initWithRootController (you cannot wire the root viewcontroller yourself...)TableView - have to programatically initWithFrame or else the table view will not update and you will end up with all cells selected (visually only)I think you need only to init the tabbar (if you linkit in IB of course).Of course, I may be wrong :-)
From the second Beta version,NSLog got messed up. Instead of printing it on the xcode console, the NSLog statements are getting printed on the system log in the Console App ( u can find this application in Application ->utilities ->Console). u can some post earlier related to the same issue.From the second Beta version,NSLog got messed up. Instead of printing it on the xcode console, the NSLog statements are getting printed on the system log in the Console App ( u can find this application in Application ->utilities ->Console). u can some post earlier related to the same issue.

 

If you really want to use the xcode debugging console, use the plain old:

printf ("%s\n", [yourNSString UTF8Sttring]);

 

M.

Link to comment
Share on other sites

I've got 2 questions for anyone out there with an opinion.

 

First off a bit of background information about the application: I've to a few UIViewControllers linked into my window all being run by my AppDelegate.

 

1. What is the "proper" way to change from one view (UIViewController) to another? I can use IB to wire a button directly to the AppDelegate and just use [window addSubview:viewController2.view] but this feels dirty. I can also have a method in my AppDelegate to deal with displaying/hiding views and call it directly from my UIViewController using something like this: [(AppDelegate*)[[uIApplication sharedApplication] delegate] changeView]. Which of these do you suggest and why?

 

2. Given a solution to the above problem how do you animate the changing of the UIViewControllers views?

EDIT: Disregard number 2. I successfully figured out how to animate views

 

Thanks

Link to comment
Share on other sites

2. Given a solution to the above problem how do you animate the changing of the UIViewControllers views?

EDIT: Disregard number 2. I successfully figured out how to animate views

 

Can you post how ?

Link to comment
Share on other sites

So, I used IB to wire up two view controllers (named viewController and viewController2) each with one view and each view having one button. I used

[window addSubview:viewController.view]

to add the view to the window and display it. You'll have to add the Quartz framework to your project and then put <QuartzCore/QuartzCore.h> in the header file to get the core animation classes. From there its pretty simple to get things animated. The code below will use a fade transition and an EaseInOut transition type but it is trivial to use any of the others once you get this working. Insert a new view and get the animation going with

[window insertSubview:newView atIndex:index];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.75];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[window layer] addAnimation:animation forKey:@"SomeKeyName"];

 

That should get you going with your view animations.

Link to comment
Share on other sites

Haven't tried yet.... but i guess this is just like the other cases:NavigationController - have to programatically initWithRootController (you cannot wire the root viewcontroller yourself...)TableView - have to programatically initWithFrame or else the table view will not update and you will end up with all cells selected (visually only)I think you need only to init the tabbar (if you linkit in IB of course).Of course, I may be wrong :-)

@mmk: do you know what the equivalent method is (like initWithRootController) for UITabController? I didnt find it in the UIToolbarController docs.

 

Oh, and back on topic, anyone got Tabbars working in IB? They don't seem to appear unless I recreate them programmatically in my code. I checked the frame of the Tabbar I inserted into my nib, and during runtime, it's always 0 width, 0 height, although resetting the frame/bounds is still not enough to get the Tabbar to appear...I need to manually alloc/init it, and add it as a subview of my main window before I see it.

so did anyone get tabbars working in IB yet? if there are any success stories, can you post a simple project that uses an xib to generate the tabbar, similar to the sdk's cocoa toolbar template (but using IB)?

 

thanks

Link to comment
Share on other sites

@mmk: do you know what the equivalent method is (like initWithRootController) for UITabController? I didnt find it in the UIToolbarController docs.

 

 

so did anyone get tabbars working in IB yet? if there are any success stories, can you post a simple project that uses an xib to generate the tabbar, similar to the sdk's cocoa toolbar template (but using IB)?

 

thanks

Ok. Here is a simple walkthrough on getting the tabbars working. In my example, I assume that you have two View Controllers in the IB. ViewController1 and ViewController2.

1. Drag the TabBarController into the Interface Object Window (where it shows all the controllers with their views)

2. Create a outlet in your app delegate class as tabBarController and wire it to the newly added TabBarController.

3. Double click on the ViewController1 to open it and drag a tab bar item from the library into it. Change its properties, text and image.

4. Repeat step 3 for ViewController2

5. Right click tab bar controller, scroll down in the black popup box, drag from the Multi-Outlets viewControllers to ViewController1, drag again to ViewController2. Noe, everything is wired up.

6. Now, in you app delegate class in method applicationDidFinishLaunching, paste the code below

 [window addSubView: tabBarController.view];
[window makeKeyAndVisible];

Link to comment
Share on other sites

 Share

×
×
  • Create New...