Is it possible to call method from one class to another where two classes from two different parent class.Suppose one from UIImage class and another from UIViewController class???? thanx for reply.
+1
A:
Yes, one of the cool things about Objective-C is that you can call a method on any object, even if it doesn't respond. Although not as robust as in Objective-C's father, SmallTalk (yes, SmallTalk is the dad and C is the mom, don't ask), it's still pretty powerful. So let's say you have something like this:
- (void)doSomethingToThis: (id)thisObject { [thisObject doSomething]; }
Then later...
//... UIImage *thisImage = ... UIViewController *thisController = ... [self doSomethingToThis: thisImage]; [self doSomethingToThis: thisController]; //...
Something like this will compile just fine, but be warned if UIImage
and UIViewController
don't both respond to doSomething
, then you could end up with a crasher (depends on how you have the compiler flags set, but I believe by default you'll get a crash).
Gordon Worley
2009-09-30 11:18:18
Nice answer, but I am not sure it is the correct answer for the question. Heck, I have no clue what the question is.
PeyloW
2009-09-30 12:43:29