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 Oct 20, 2009, 12:31 AM   #1
Earendil
macrumors 68000
 
Earendil's Avatar
 
Join Date: Oct 2003
Location: Washington
UITabBar - Need high level explanation

Okay, so I'm new to Objective C, Xcode, and thus also the iPhone SDK
However I'm not to new programming or OO thinking, so feel free to explain things in terms of regular SE ideas.

So I've written my first little app. I use a UITabBar to flip between two screens, the main functionality of the app, and a page of preferences.

Everything has worked fine, and I'm starting to get a hang of things, but here is where my understanding of what is actually going on all breaks down.

On the preferences page is a button, that when pressed needs to change a label on the the first page. I have an event that captures the button press just fine, but when it goes to change the label the program crashes. I'm not great with debugging things in Xcode yet, but if I had to hazard a guess, I'd say it was some sort of scope problem?

I'm 99.99% sure I have everything connected properly in IB, as I am fully able to create a button in a tab that modifies a label within the currently selected tab. It's modifying a tab that isn't currently being viewed that has me stuck.

When a UITabBar is used, does only one "tab" exist at a time? This might explain it.

My second thought was "I'll just store the preference state in a few variables, and upon loading the first tab, use those variables to modify the UI!". However I can't find any sort of "on tab load" event.

I've searched high and low for an answer, and now I'm "giving up" and coming to you guys for help. It's always the worst when you can't find an answer to a seemingly simple problem, because that usually means it's stupid-simple.
__________________
Current: MacMini 2ghz / iPod Touch 2g / iPhone 4g
Retired: Alum Powerbook 1.25ghz / 4gb iPod Mini

"ooo! They have the internet on computers now!" - Homer J. Simpson
Earendil is offline   0 Reply With Quote
Old Oct 20, 2009, 10:34 AM   #2
ghayenga
macrumors regular
 
Join Date: Jun 2008
Quote:
Originally Posted by Earendil View Post
Okay, so I'm new to Objective C, Xcode, and thus also the iPhone SDK
However I'm not to new programming or OO thinking, so feel free to explain things in terms of regular SE ideas.

So I've written my first little app. I use a UITabBar to flip between two screens, the main functionality of the app, and a page of preferences.

Everything has worked fine, and I'm starting to get a hang of things, but here is where my understanding of what is actually going on all breaks down.

On the preferences page is a button, that when pressed needs to change a label on the the first page. I have an event that captures the button press just fine, but when it goes to change the label the program crashes. I'm not great with debugging things in Xcode yet, but if I had to hazard a guess, I'd say it was some sort of scope problem?

I'm 99.99% sure I have everything connected properly in IB, as I am fully able to create a button in a tab that modifies a label within the currently selected tab. It's modifying a tab that isn't currently being viewed that has me stuck.

When a UITabBar is used, does only one "tab" exist at a time? This might explain it.

My second thought was "I'll just store the preference state in a few variables, and upon loading the first tab, use those variables to modify the UI!". However I can't find any sort of "on tab load" event.

I've searched high and low for an answer, and now I'm "giving up" and coming to you guys for help. It's always the worst when you can't find an answer to a seemingly simple problem, because that usually means it's stupid-simple.
The viewControllers in those two separate tabs don't necessarily know anything about each other.

There's a bunch of different ways you could communicate that information from one to the other. Set variables on the shared application delegate and use those to reference them and send messages to each other. If you're using a tabBarController it has an array of the viewControllers it's managing, have one view register for a notification and the other post the notification when it gets the event. Set up key-value observing on a global variable so when viewController in tab 2 changes the value viewController in tab 1 detects it, etc.
ghayenga is offline   0 Reply With Quote
Old Oct 20, 2009, 07:13 PM   #3
drf1229
macrumors regular
 
Join Date: Jun 2009
Ok first of all, are you correctly using the IBAction? Second, did you connect the two views in Interface builder? If both of those are correct in both code and interface builder, you need to assign the label you are changing as a property. Doing this is simple. In the view with the label header file at the bottom but before @end, put this:
Code:
@property(nonatomic, retain) UILabel *YourLabelName;
This way you can access the label through any view that is connected to the view with the label via IBOutlet. The reason for the crash is most likely an misconnection in interface builder, so double check you don't get any errors/warnings in interface builder. If problems continue, feel free to inquire, I'd be glad to help.
drf1229 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

Similar Threads
thread Thread Starter Forum Replies Last Post
21.5 entry level vs. 21.5 high end late 2013 Escritor iMac 2 Nov 26, 2013 04:14 AM
[iPhone] Bubble Level - Elegant and accurate level app - FREE - out today! Phoenix Mobile iPhone and iPod touch Apps 1 Mar 26, 2013 11:21 PM
Math, physics and chemistry on high level Paludan iPad Tips, Help and Troubleshooting 1 Jan 10, 2013 01:09 PM
Mid Level Mac Mini outperform base Level Imac 21.5 (2011) tears2040 Mac mini 9 Oct 26, 2012 05:27 AM
High Level TECH TALK - Printers chefwong Mac Peripherals 0 Sep 22, 2012 05:22 PM

Forum Jump

All times are GMT -5. The time now is 05:01 PM.

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

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