PDA

View Full Version : [Resolved] warning when trying to override designated initializer, please help.




webznz
Apr 5, 2011, 10:02 PM
Hi there I am going through a tutorial "iPhone Programming by The big Nerd Ranch pg305" regarding web services and basically I'm just trying to get myself familiar with NSURLConnection, NSURLRequest and NSURL and how they are used and how they interact with tableViews etc.

I am currently trying to override the designated initializer initWithStyle: but its throwing warnings I haven't seen before, any suggestions of how to fix this warning would be greatly appreciated.


- (id)initWithStyle:(UITableViewStyle)style {
if (self = [super initWithStyle:style]) { //UIViewController may not respond to '-initWithStyle'
songs = [[NSMutableArray alloc] init];
}
return self;
}


One thing I find interesting is that I have looked at both UIView and UIViewController class refrences on the apple developer library and neither have a method "initWithStyle" is this an error in there book do you think?



PhoneyDeveloper
Apr 5, 2011, 10:10 PM
That method is found on UITableViewController.

Why do you call it the designated initializer?

webznz
Apr 5, 2011, 10:33 PM
Editing... didnt read your post correctly, I have seen it now.. so I guess that means I have to change my interface?

@interface RSSTableViewController : UIViewController {

to

@interface RSSTableViewController : UITableViewController {


well at least thats what Im thinking.. will give it ago :)

also:
I called it designated initializer because thats how they refer to it in the book :P

webznz
Apr 5, 2011, 10:37 PM
BOYA! that worked :)

@interface RSSTableViewController : UITableViewController {

weird they didn't even reference that in the book.. might be obvious to people who have alot more experience, but for noobies like me who use the book its a hard thing to pick up on... then again maybe it was done on purpose to help teach me something :P

anyway thankyou for the nudge in the right direction.

PhoneyDeveloper
Apr 5, 2011, 10:42 PM
initWithNibName: is the UIViewController designated initializer. I'm guessing they haven't explained what a designated initializer is yet.

admanimal
Apr 5, 2011, 10:48 PM
The designated initializer for a class is usually the one with the most parameters and is the one ultimately called by all of the other initializers in the initializer chain. It is responsible for making sure all of the class' instance variables are properly initialized. When creating a subclass, you should override the super class' designated initializer in case someone tries to initialize the subclass using one of the superclass' initializers.

webznz
Apr 5, 2011, 11:19 PM
initWithNibName: is the UIViewController designated initializer. I'm guessing they haven't explained what a designated initializer is yet.

I did know this and hence the confusion on my part... nothing I can see in this tutorial even hints at it being from the UITableViewController.. but I guess I should have known from the

:(UITableViewStyle)style

chown33
Apr 6, 2011, 01:09 AM
I did know this and hence the confusion on my part... nothing I can see in this tutorial even hints at it being from the UITableViewController..

What is the URL of the tutorial? Or is it a book with a website?

Maybe you can send them feedback about using terms like designated initializer before they're defined.

Complaints here won't really make a difference. You have to tell someone who's in a position to change things, or you change the book/tutorial you're using.

webznz
Apr 6, 2011, 03:21 PM
I wasn't so much complaining other than surprised that they didn't mention the step of changing the designated initalizer in the part where they tell you to make the UIViewController subclass in this chapter. I have pretty much read the entire ebook, (while waiting for the book I ordered to come) but it will take a few more times of going through exercises to get a handle on stuff I have obviously forgotten. The reason I skipped over to this chapter is because I needed to learn about NSURL, NSURLRequest and NSURLConnection.

I have joined up with their forums and might check to see if this has been brought up before.

chown33
Apr 6, 2011, 03:24 PM
I have joined up with their forums and might check to see if this has been brought up before.

So others who read this thread in the future can benefit, please post the URL of their website.

dejo
Apr 6, 2011, 03:33 PM
The reason I skipped over to this chapter is because I needed to learn about NSURL, NSURLRequest and NSURLConnection.
Perhaps the information you found missing was actually covered in the chapters you skipped over.

webznz
Apr 6, 2011, 04:52 PM
heres the info on the book
main site: http://www.bignerdranch.com/
Books page: http://www.bignerdranch.com/book/iphone_programming_the_big_nerd_ranch_guide
Books Forum: http://forums.bignerdranch.com/viewforum.php?f=9&sid=b6ad7afda6f74942945e92f9f4a5ea85

@dejo
I have read 90% of the book, chapters 1-25 via an e-book while I was waiting for my ordered book to arrive.. took about 4 or 5 weeks since I live in hobbiton :P the book covers the stuff about designated initializer in chapter 2 page 35, The exercise I was working on is in chapter 21 page 303... It's understandable I forgot about this.. I should have checked the index but I wasn't really aware there was a problem until I received the errors. At the end of the day maybe it would be a little more helpful to mention after implementing the subclass that if your writing the view (persistently) you should look to change the class being referenced in your view controller.

dejo
Apr 6, 2011, 05:28 PM
I have read 90% of the book, chapters 1-25 via an e-book while I was waiting for my ordered book to arrive.. took about 4 or 5 weeks since I live in hobbiton :P the book covers the stuff about designated initializer in chapter 2 page 35, The exercise I was working on is in chapter 21 page 303... It's understandable I forgot about this.. I should have checked the index but I wasn't really aware there was a problem until I received the errors.
I was thinking you might've skipped the section on subclassing of the UITableViewController rather than the explanation of the designated initializer but I'm probably wrong there too, huh? :)

At the end of the day maybe it would be a little more helpful to mention after implementing the subclass that if your writing the view (persistently) you should look to change the class being referenced in your view controller.
I have no idea what you're trying to say here. Sorry. :confused:

webznz
Apr 6, 2011, 06:00 PM
Basically, I was reading this book trying to learn as much as possible as fast as possible.. so I have obviously forgotten alot of the stuff I have read from this book. I'm still new to objective-c and am slowly getting there.

I have read most of this book, got a general sense of whats going on, then I have watched episode 1 to about 13 of the stanford iphone programing lectures on youtube (which are amazingly helpful for people who learn better from listening than reading) this gave me alot of context to the stuff I had read and "remembered" :) ... and now I am going through the book (now that i have it) and going through the tutorials in it gaining a small amount of experience by going over anything that I don't understand.

I'm not the fastest learner in the world I have come off the back of a brain injury and often find myself having to read or go over things several times before they stick... one thing I am however is persistent.

Also I'm not claiming to be better than anyone here, because its obvious I'm not I'm just trying my best to learn a new language that I know will be beneficial to me in the future. I would like to point out one thing though, often when reading some peoples replies on here I come out feeling completely **** about myself... I'm sure its the same for some others. Maybe I bring it on myself... anyway just saying haha.

In response to the first part of your last post dejo, I must know a little something about subclassing if I ended up realizing how to solve the problem (with a little nudge in the right direction from PhoneyDeveloper) it's just I was looking in the wrong classes and he pointed out the right one... more an experience issue than an understanding issue?...

Second part of your post.. I was just saying maybe they could have been a-little clear in their instructions and included the stuff about designated initializer or at-least hinted not to forget about it...

wow.. long post.