我有太多的代碼知道我需要在這裏引用,但在我的應用程序委託我有一個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