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

mcannell

macrumors member
Original poster
Dec 20, 2008
36
0
I have a simple splash screen that displays a picture. Over the picture is a button that says "Continue"

I have the button connected to an IBAction in the implementation file for the nib.

When I press that button I want to call "- (void)loadMainMenuScreen" which is located in the RootViewController.m file.

Someone please let me know how to do something like this (it should be simple)!

Also, please be specific. Too often I read responses that tell what needs to be done but are so vague that the person asking the question has to ask how to do the tip being offered.
 

mcannell

macrumors member
Original poster
Dec 20, 2008
36
0
I thought I had it but I must be on to something....

I added a View Controller to my nib file.
I set its class to RootViewController & voila, the method I want to call is listed in the Actions list.
I right-clicked and dragged a connection to the RootViewController and selected my desired method from the drop down and built the project.

On testing in the Simulator I get an error when I click the button.

Here is the error:

Code:
2008-12-23 02:21:46.808 MyAPP[48605:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[CAContextImpl toggleView]: unrecognized selector sent to instance 0x453ac0'

Am I close? Can someone please help ASAP?
 

mcannell

macrumors member
Original poster
Dec 20, 2008
36
0
One step closer....

I forgot to de-link my button FROM the view and relink FROM the RootViewController. As soon as I fixed this connection I don't get the error when I click the button. I get a new error, though. a NON-BOLD error.

Code:
Loading program into debugger…
GNU gdb 6.3.50-20050815 (Apple version gdb-960) (Sun May 18 18:38:33 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".warning: Unable to read symbols for "/System/Library/Frameworks/UIKit.framework/UIKit" (file not found).
warning: Unable to read symbols from "UIKit" (not yet mapped into memory).
Program loaded.
sharedlibrary apply-load-rules all
Attaching to program: `/Users/MyName/Library/Application Support/iPhone Simulator/User/Applications/012F2C1B-1D49-4CA3-A212-303D3D29F481/MyApp.app/MyApp', process 48873.

The UIKit Framework IS in my project.
I also am importing it into BOTH header files using
Code:
#import <UIKit/UIKit.h>
 

neil.b

macrumors member
Nov 20, 2008
65
0
I posted a similar question a while back and got two different answere, both of which worked.

1) EXTERN the method you want to call in the RootViewController interface definition.

or (the one I used)

2) In the class that you want to call the RootViewController method from, define an ID that you set to point to the RootViewController when the RootViewController loads;

In the class, I'll call it MyClass for illustration;

Code:
//In the interface
ID *RootView;

Code:
//In the implementation
@synthesize RootView;

Then in RootViewController, somewhere where it loads/inits;

Code:
MyClass.RootView = self;
Then in MyClass, when you want to call the RootViewMethod;

Code:
[RootView theMethodName];
 

neil.b

macrumors member
Nov 20, 2008
65
0
I think I may have given you a more complicated solution than you need. I should avoid replying to stuff when I've just woken up :)

The UIKit.h warning you're seeing is normal if you're using the iPhone Simulator. Well, I've come to think it is as I see it all the time but it doesn't appear when building for a device.

So, your problem...

Could do with knowing more detail about how you've set up the .xib file. Where is the splash screen and the button - in the same .xib file that contains the RootViewController?
 

mcannell

macrumors member
Original poster
Dec 20, 2008
36
0
I can deal with 4 lines.

I got 2 errors though....

Code:
@synthesize RootView;
-->error: no declaration of property 'RootView' found in the interface


Code:
SplashScreen.RootView = self;
-->error: 'SplashScreen' undeclared (first use in this function)



I added
Code:
#import "SplashScreen.h"

and got a new error:
Code:
SplashScreen.RootView = self;
-->error: syntax error before '.' token
 

mcannell

macrumors member
Original poster
Dec 20, 2008
36
0
I also get 2 warnings, one is expected

Code:
[RootView myMethod];
-->warning: invalid receiver type 'ID *'
--> warning: no '-myMethod' method found

I added to the top of MyClass.h

Code:
#import "RootViewController.h"

And the second warning went away, which makes sense.
 

mcannell

macrumors member
Original poster
Dec 20, 2008
36
0
I did the import before because it made sense and I tried the @property too but I got an error because I don't know the syntax.

Code:
@property (nonatomic, retain) ID *RootView;
-->error: property 'RootView' with 'retain' attribute must be of object type

I tried copy too
 

neil.b

macrumors member
Nov 20, 2008
65
0
I did the import before because it made sense and I tried the @property too but I got an error because I don't know the syntax.

Code:
@property (nonatomic, retain) ID *RootView;
-->error: property 'RootView' with 'retain' attribute must be of object type

I tried copy too

Apologies, it should be "id" not "ID".

Edit to clarify: it should be "id RootView" and not "id *RootView". I forgot that with "id" the pointer is implied.
 

mcannell

macrumors member
Original poster
Dec 20, 2008
36
0
This seems to work:

Code:
@property (nonatomic, assign) ID *RootView;

but I still have the error in the RootViewController.m

Code:
SplashScreen.RootView = self;
-->error: syntax error before '.' token
 

mcannell

macrumors member
Original poster
Dec 20, 2008
36
0
changed to 'id' but still:

Code:
- (void)viewDidLoad {
SplashScreen.RootView = self;
-->error: syntax error before '.' token

(...)

}

I am using SplashScreen in place of MyClass because:

Code:
@interface SplashScreen : UIView {

(...)

}
 

neil.b

macrumors member
Nov 20, 2008
65
0
This seems to work:

Code:
@property (nonatomic, assign) ID *RootView;

but I still have the error in the RootViewController.m

Code:
SplashScreen.RootView = self;
-->error: syntax error before '.' token

You must have an instance of the SplashScreen view controller defined somewhere in RootViewController?
 

mcannell

macrumors member
Original poster
Dec 20, 2008
36
0
You must have an instance of the SplashScreen view controller defined somewhere in RootViewController?

I have this:

#import "SplashScreen.h"

@implementation RootViewController

(...)

- (void)viewDidLoad {

SplashScreen.RootView = self;

(...)

}


I have only a SplashScreen.h, SplashScreen.m, & SplashScreen.xib
I don't have a specific SplashScreenViewController... files
 

neil.b

macrumors member
Nov 20, 2008
65
0
I'm new to this myself but from what I've learned there are a few "rules" that you should stick to until you find your feet at least.

- One View per .nib/.xib.

- For every View you should have a View Controller

On the second point, what that means is that your RootViewController should be thought of as a view controller controller in that it controls your applications various view controllers who in turn control their own views and interactions.

That's quite a simplistic view but I don't find it easy to explain.
 

mcannell

macrumors member
Original poster
Dec 20, 2008
36
0
I added SplashScreenViewController

@class'd it
declared it
@property'd it

#Imported it
@synthesized it

I still get the syntax error before '.' message
 

neil.b

macrumors member
Nov 20, 2008
65
0
It makes sense.

But what do I put in the SplashScreenViewController.h & .m files to fix this error?

Right, well in the RootViewController interface you need a property that is an instance of your SplashScreenViewController, say;

Code:
@interface RootViewController : UIViewController {
    SplashScreenViewController *splashViewController;
}

@property (nonatomic, retain) IBOutlet SplashScreenViewController *splashViewController;

Then, with the "RootView" property in the SplashScreenViewController definition and not in SplashScreen, in your RootViewController init you can do the;

splashViewController.RootView = self;
 

mcannell

macrumors member
Original poster
Dec 20, 2008
36
0
Builds but I get more warnings... Plus I can't get the button to connect now.

RootViewController.m
Code:
splashScreenViewController.RootView = self;
-->warning: passing argument 1 of 'setRootView:' from incompatible pointer type


SplashScreenViewController.m
Code:
[RootView loadMainMenuScreen];
-->warning: invalid receiver type 'id *'

For some reason that escapes me, I can NEVER get buttons to work in a ViewController subclass. I can only get them to work in the class files.

Code:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MainViewController 0x454580> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key myButton.'
 

neil.b

macrumors member
Nov 20, 2008
65
0
Builds but I get more warnings... Plus I can't get the button to connect now.

RootViewController.m
Code:
splashScreenViewController.RootView = self;
-->warning: passing argument 1 of 'setRootView:' from incompatible pointer type


SplashScreenViewController.m
Code:
[RootView loadMainMenuScreen];
-->warning: invalid receiver type 'id *'


The "RootView" definition should be "id RootView;"

You'll need to reconfigure your button->action stuff to take into account that you now have a SplashScreenViewController to handle the interaction. Define an action in the SplashScreenViewController and link the button to that then in the implementation of the action call the method in the RootViewController.

It would be too much to type to go through every step but you seem to have the basics.

Without seeing the files/code, it might be best to start again from scratch and build it correctly.
 

mcannell

macrumors member
Original poster
Dec 20, 2008
36
0
You'll need to reconfigure your button->action stuff to take into account that you now have a SplashScreenViewController to handle the interaction. Define an action in the SplashScreenViewController and link the button to that then in the implementation of the action call the method in the RootViewController.


I already did all this but I can't get the button to work... even if it just calls

Code:
- (IBAction)continueButton:(id)sender {
	NSLog(@"test");
}

Plus I was told by another developer in an email to make it

Code:
splashScreenViewController.RootView = self.view;

and that got rid of all my warnings. Now if I can just get the button click to not throw exceptions I think we have it
 

neil.b

macrumors member
Nov 20, 2008
65
0
Plus I was told by another developer in an email to make it

Code:
splashScreenViewController.RootView = self.view;

and that got rid of all my warnings. Now if I can just get the button click to not throw exceptions I think we have it

Hang on;

Code:
splashScreenViewContoller.RootView = self.view
is pointing at the view in RootViewController and not the RootViewController itself, which is wrong. You want it to point to RootViewController as you want to access one of the methods of RootViewController not a method of the view of RootViewController.
 

mcannell

macrumors member
Original poster
Dec 20, 2008
36
0
is pointing at the view in RootViewController and not the RootViewController itself, which is wrong. You want it to point to RootViewController as you want to access one of the methods of RootViewController not a method of the view of RootViewController.

It is pointing to and pointing from the File's Owner... I didn't even have a ViewController in it.

I added a viewController to the xib and set it's class to SplashScreenViewController. Then I connected to button to & from...

It builds, it loads....

When I press the button it is supposed to print "test" in the log but it prints...

Code:
Loading program into debugger…
GNU gdb 6.3.50-20050815 (Apple version gdb-960) (Sun May 18 18:38:33 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".warning: Unable to read symbols for "/System/Library/Frameworks/UIKit.framework/UIKit" (file not found).
warning: Unable to read symbols from "UIKit" (not yet mapped into memory).
Program loaded.
sharedlibrary apply-load-rules all
Attaching to program: `/Users/MyName/Library/Application Support/iPhone Simulator/User/Applications/6451D117-6621-4652-8933-A4B85A711EE0/MyApp.app/MyApp', process 53454.

So I am back to this....
 

mcannell

macrumors member
Original poster
Dec 20, 2008
36
0
If I build & go and click the button I get that error in the log.

If I build & go then click the big button to exit the app, then click the app icon, and THEN click the button I get this error:

Code:
Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x000000000000070b
Crashed Thread:  0
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.