problem wile calling the class from another class
hi i am new to iphone what i did is i am creating two classes named classA and classB. I am displaying 10 thumbs in classA ViewDidLoad and adding the images in classB by declaring the function.Along with images sound is also added.While click on thumb it will be displayed on imageview.开发者_StackOverflow社区 it works fine. But After completion of sound play i am calling the classA viewDidLoad by creating object of it.It goes to classA but it displays first selected image every time what is problem. how can i call again calssA pls post some code thank u .
If I understand what you mean correctly, you're trying to call different selectors to display images?
I don't think UIKit calls work via instantiating a new instance of a class, and UIImageView is part of UIKit.
The way I always got this to work is by defining a "sharedInstance". This works as such:
In your .h file for ClassA, add the following:
+ (ClassA *)sharedInstance;
In your .h file for ClassB, add the following:
+ (ClassB *)sharedInstance;
Then, in the .m file for ClassA, add the following:
static ClassA *sharedInstance = nil;
- (id)init
{
if (sharedInstance) {
[self dealloc];
} else {
sharedInstance = [super init];
}
return sharedInstance;
}
+ (ClassA *)sharedInstance
{
return sharedInstance ? sharedInstance : [[[self alloc] init] autorelease];
}
..and do the same for ClassB.
Now you can call different selectors without having to instantiate ClassA nor B. Don't forget to #import "ClassA.h"
or "ClassB.h"
!
Then you can call selectors as such: [[Class A sharedInstance] doSomething];
精彩评论