Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-06-2008, 03:42 PM   #1 (permalink)
Registered Member
 
chuck's Avatar
 
Join Date: Aug 2008
Location: Berlin, Germany
Posts: 87
chuck is on a distinguished road
Default Can't get view to load after following iPhone SDK Final tutorial

Hi,

I recently watched the Hello World Final SDK tutorial and I've been using that and the HelloWorld app from Apple as examples. I have the basic window-based app set up and it initializes, but I don't think the view loads. I imagine this is something really stupid that I just need to learn and if someone could help me get over this initial hump, I'd greatly appreciate it. Right now, I just want an app where I type something in the search bar and it appears in the text view below which I'll use as a foundation to make something really cool.

Here is my code:

MyAppDelegate.h (unmodified from template)

MyAppDelegate.m
Code:
#import "MyAppDelegate.h"

@implementation MyAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(UIApplication *)application {	
	NSLog( @"Initialized." );

	// Override point for customization after app launch	
    [window makeKeyAndVisible];
}

- (void)dealloc {
	[window release];
	[super dealloc];
}

@end
MainView.h
Code:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface MainView : UIView <UISearchBarDelegate> {
    IBOutlet UITextView *mainText;
    IBOutlet UISearchBar *searchBar;
}

@property (nonatomic, retain) UITextView *mainText;
@property (nonatomic, retain) UISearchBar *searchBar;

@end
MainView.m
Code:
#import "MainView.h"

@implementation MainView

@synthesize mainText;
@synthesize searchBar;

- (void)viewDidLoad {
	NSLog( @"At least the delegate loads." );
	searchBar.delegate = self;
}

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
    // When the user presses return, take focus away from the text field so that the keyboard is dismissed.
	[self resignFirstResponder];
	// Invoke the method that changes the greeting.
	
	mainText.text = searchText;
	NSLog( @"This should have been set.");
}

- (void)dealloc {
	[string release];
	[mainText release];
	[searchBar release];
	[super dealloc];
}

@end
In the console I only see the following message:

[Session started at 2008-08-06 22:29:43 +0200.]
2008-08-06 22:29:45.465 My[879:20b] Initialized.

I get no errors. I know it's initializing, but it's not running ViewDidLoad. Perhaps I have to specifically call the view to load? Anyway, as I said, if anyone could help, I'd greatly appreciate it. I'm using iPhone SDK Final. Thanks in advance!
chuck is offline   Reply With Quote
Old 08-07-2008, 03:37 AM   #2 (permalink)
Registered Member
 
chuck's Avatar
 
Join Date: Aug 2008
Location: Berlin, Germany
Posts: 87
chuck is on a distinguished road
Default More Information

I'm still banging my head against the wall on this. I recently added the following code to MainView.m:

Code:
- (BOOL)respondsToSelector:(SEL)sel {
    NSLog(@"Queried about %@", NSStringFromSelector(sel));
    return [super respondsToSelector:sel];
}
and now I get the following on the console, so it's apparently at least recognizing this class:

Code:
[Session started at 2008-08-07 10:19:28 +0200.]
2008-08-07 10:19:36.674 My[940:20b] Queried about actionForLayer:forKey:
2008-08-07 10:19:36.675 My[940:20b] Queried about displayLayer:
2008-08-07 10:19:36.677 My[940:20b] Queried about drawLayer:inContext:
2008-08-07 10:19:36.678 My[940:20b] Queried about _layoutSublayersOfLayer:
2008-08-07 10:19:36.679 My[940:20b] Queried about animationDidStart:
2008-08-07 10:19:36.679 My[940:20b] Queried about animationDidStop:finished:
2008-08-07 10:19:37.071 My[940:20b] Initialized.
If anyone could give me any help, I'd be very grateful. Thanks!
chuck is offline   Reply With Quote
Old 08-07-2008, 07:32 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 355
Bucky is an unknown quantity at this point
Default

I haven't looked at the tutorial, but do you need this in the applicationDidFinishLaunching: method?

Code:
MainView *mainView = [[MainView alloc] init];

[window addSubView:mainView];
I say this because the viewDidLoad: method obviously hasn't run, since the console did not have "At least the delegate loads"
Bucky is offline   Reply With Quote
Old 08-07-2008, 10:28 AM   #4 (permalink)
Registered Member
 
chuck's Avatar
 
Join Date: Aug 2008
Location: Berlin, Germany
Posts: 87
chuck is on a distinguished road
Default

Thanks for your answer. However, when I try to build, I get the following warning:

Code:
'UIWindow' may not respond to '-addSubView:'
When I try to run, I see the following cryptic message in the console:

Code:
2008-08-07 17:21:43.611 My[4016:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIWindow addSubView:]: unrecognized selector sent to instance 0x458200'
2008-08-07 17:21:43.613 My[4016:20b] Stack: (
    2530709835,
    2459984123,
    2530739018,
    2530732364,
    2530732562,
    9514,
    816174362,
    816210018,
    2472847710,
    2530212677,
    2530213112,
    829005112,
    829005309,
    816175835,
    816221412,
    9240,
    9094
)
The thing I can't figure out is that I can indeed see the view fields in the iPhone Simulator, it's just the search field doesn't do anything nor does viewDidLoad even run. I'm guessing the Interface Builder already set up some kind of relationship from the window to the MainView, but I don't know how you would access it. Any ideas?

Last edited by chuck; 08-07-2008 at 10:32 AM.
chuck is offline   Reply With Quote
Old 08-07-2008, 12:09 PM   #5 (permalink)
Registered Member
 
chuck's Avatar
 
Join Date: Aug 2008
Location: Berlin, Germany
Posts: 87
chuck is on a distinguished road
Default

Update: I changed viewDidLoad to didMoveToWindow and now "At least the delegate loads" appears on the console, although it still doesn't work...
chuck is offline   Reply With Quote
Old 08-07-2008, 01:59 PM   #6 (permalink)
Registered Member
 
chuck's Avatar
 
Join Date: Aug 2008
Location: Berlin, Germany
Posts: 87
chuck is on a distinguished road
Default

Final Update for Today: I believe I need to set up the project anew for a View-based application instead of a Window-based application, so I can get a View Controller. I'm pretty sure how to do it now, but I'm quite too tired tonight to keep on. I'll update again tomorrow with my progress.
chuck is offline   Reply With Quote
Old 10-04-2008, 10:54 PM   #7 (permalink)
jag
New Member
 
Join Date: Oct 2008
Posts: 1
jag is on a distinguished road
Default

Hi,

I'm not sure if you figured this out or not (2 months later) but, I found this thread searching for the same error message. Turns out it's just a typo, it should be addSubview (with a lowercase v) instead of addSubView. I guess subview is one word, not two...

I thought it might be helpful to have this up here in case anyone else stumbles across this with google...

-Jeremy
jag is offline   Reply With Quote
Old 10-04-2008, 10:58 PM   #8 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 22
airjordan12345 is on a distinguished road
Default

Let us know how it went.

The project type you select is essential, as there is a big difference between them.

Also, even though your code might be written correctly, you also need to make sure your connections in Interface Builder are set up correctly.

Try it out tomorrow with the View Controller, as a view-based application.

If that doesnt work then go ahead and share your project so I can see what is wrong.

Cheers,
Felipe.
airjordan12345 is offline   Reply With Quote
Old 05-14-2010, 10:10 AM   #9 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 3
Cardinal is on a distinguished road
Default Thank you

Quote:
Originally Posted by jag View Post
Hi,

I'm not sure if you figured this out or not (2 months later) but, I found this thread searching for the same error message. Turns out it's just a typo, it should be addSubview (with a lowercase v) instead of addSubView. I guess subview is one word, not two...

I thought it might be helpful to have this up here in case anyone else stumbles across this with google...

-Jeremy

Thank you for posting this. I wasted about an hour trying to figure this out before I searched this forum.
Cardinal is offline   Reply With Quote
Reply

Bookmarks

Tags
uisearchbar, uisearchbardelegate, viewdidload

Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 336
9 members and 327 guests
chiataytuday, coolman, givensur, ipodphone, jbro, mtl_tech_guy, Punkjumper, vilisei, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,881
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:15 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0