views:

31

answers:

2

Hi!

I'd like to create a subclass of UIAlertView to implement my own defaut behaviors when users click on the dialog's buttons.

It would be awesome if someone would guide me through it or just point me to some guide about subclassing?

Thanks!

+1  A: 

There is not much to say about subclassing in Objective C.

The standard syntax looks like this.

@interface NSObjectSubClassedObject : NSObject {

}

Two things to mention: Multi-Inheritance is not supported and there's another method to "subclass" certain objects called Categories.

Henrik P. Hessel
There is a bit more to it in that some Cocoa classes require certain methods to be handled by the developer when subclasses, and this described in the Guides and Class References.
Philip Regan
Okay so I have do something like @interface CustomUIAlertView : UIAlertView {} and then overrides methods from the superclass something like this? - (void)aTest { // MY STUFF [super aTest]; } ? If it's simple as this then it's amazing! Thanks! ( formatted version of my example http://pastie.org/1189589 ) (StackOverflow should definitively add linebreaks to comment lol)
Tom
The documentation will also let you know which methods you should not—or ever—override. The actual task of subclassing is easy, but there is definitely some strategy involved.
Philip Regan
I'm sorry for my noobiness but where is "Guides and Class References" ? I've looked on google for it but did not find nothing relevant :/ Thanks :)
Tom
The Guides and Class References are part of the documentation that comes with Xcode.
Philip Regan
+2  A: 

You most likely don't want to subclass UIAlertView. Rather you want to implement the UIAlertViewDelegate protocol on your view controller. This will allow you to customize what happens when a user clicks a button on the alert view.

Some some examples, check out any of the sample projects listed under "Related sample code" at the protocol documentation that I've linked to above.

Robot K