我有太多的代码知道我需要在这里引用,但在我的应用程序委托我有一个NSMutableArray。然后在另一个类中,它创建一个NSMutableArray的新条目,但是在返回到另一个应该使用它显示屏幕上的类时,它不显示任何内容。将NSMutableArray计数放在类的末尾,创建它将显示数字1,然后将相同的NSLog代码放在要使用的类的起始处,返回0.NSMutableArray计数不断变化
任何想法为什么会这样是什么?
编辑:好吧,我会尽力的,包括所有相关的代码..
应用delegate.h:
@interface palettesAppDelegate : NSObject <UIApplicationDelegate> {
NSMutableArray *colourPalettesContainer;
}
@property (assign, readwrite) NSMutableArray *colourPalettesContainer;
@end
应用delegate.m:
#import "palettesAppDelegate.h"
@implementation palettesAppDelegate
@synthesize colourPalettesContainer;
- (void)dealloc {
[colourPalettesContainer release];
[super dealloc];
}
@end
Homeview.h :
#import <UIKit/UIKit.h>
#import "HandlingPalettes.h"
@interface HomeView : UIViewController {
HandlingPalettes *handlingPalettes;
}
@end
Homeview.m:
#import "HomeView.h"
#import <QuartzCore/QuartzCore.h>
@implementation HomeView
- (void)viewDidLoad {
[super viewDidLoad];
handlingPalettes = [[HandlingPalettes alloc] init];
[handlingPalettes newPalette];
}
-(void)viewWillAppear:(BOOL)animated {
NSLog(@"view will appear: %i", [dataCenter.colourPalettesContainer count]);
int numberOfExisting = [dataCenter.colourPalettesContainer count];
}
- (void)dealloc {
[handlingPalettes release];
[super dealloc];
}
@end
HandlingPalettes.h:
#import <UIKit/UIKit.h>
@interface HandlingPalettes : UIViewController {
}
-(void)newPalette;
@end
HandlingPalettes.m:
#import "HandlingPalettes.h"
#import "HomeView.h"
#import "palettesAppDelegate.h"
@implementation HandlingPalettes
-(void)newPalette {
palettesAppDelegate *dataCenter = (palettesAppDelegate *)[[UIApplication sharedApplication] delegate];
//If this is the first palette
if (dataCenter.colourPalettesContainer == nil) {
dataCenter.colourPalettesContainer = [[NSMutableArray alloc] init];
}
//Add a new palette
[dataCenter.colourPalettesContainer addObject:@"Test1", @"Test2", nil];
NSLog(@"Handling: %i", [dataCenter.colourPalettesContainer count]);
}- (void)dealloc {
[super dealloc];
}
@end
没有看到你的代码,我不知道。 – 2011-03-16 23:37:34
没有看到代码......有两件事要检查(a)它确实是* same *'NSMutableArray',并且不太可能(b)你没有删除你添加的内容。 – CRD 2011-03-16 23:44:30
[dataCenter.colourPalettesContainer addObject:@“Test”,nil]; 为什么你有多个参数呢?你不需要零... – 2011-03-16 23:58:20