相同的代码适用于 iOS 5,但不适用于 iOS 6。计数显示为 0。有什么想法吗?它应该说至少 1 作为计数,因为我已经验证 house.png 是一个有效的图像。
这是我的代码:
MyManager * myManager = [MyManager sharedInstance];
NSString *pathOfImageFile = [[NSBundle mainBundle] pathForResource:@"house" ofType:@"png"];
UIImage *myImage = [UIImage imageWithContentsOfFile:pathOfImageFile];
UIImageView * tempImageView = [[UIImageView alloc] initWithImage:myImage];
[myManager.assets addObject:tempImageView];
NSLog(@"image count: %d", [myManager.assets count]);
这是我的单身人士:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface MyManager : NSObject
{
MyManager *_sharedObject;
NSMutableArray * assets;
}
//Property Listing
@property(nonatomic,copy) NSString * postTitle;
@property(nonatomic,copy) NSString * postText;
@property(nonatomic,copy) NSString * postLink;
@property(nonatomic,copy) NSString * postCategory;
//assets
@property (nonatomic, strong) NSMutableArray * assets;
+ (id)sharedInstance;
- (void)reset;
@end
#import "MyManager.h"
@implementation MyManager
//Property Listing
@synthesize postTitle=_postTitle;
@synthesize postText=_postText;
@synthesize postLink=_postLink;
@synthesize postCategory=_postCategory;
@synthesize assets=_assets;
- (id)init
{
self = [super init];
if ( self )
{
assets = [[NSMutableArray alloc] init];
NSLog(@"Singleton Initialized...");
}
return self;
}
+ (id)sharedInstance
{
static dispatch_once_t pred = 0;
__strong static id _sharedObject = nil;
dispatch_once(&pred, ^{
_sharedObject = [[self alloc] init]; // or some other init method
});
return _sharedObject;
}
- (void)reset
{
self.postTitle =@"";
self.postText=@"";
self.postLink=@"";
self.postCategory=@"";
[self.assets removeAllObjects];
}
@end