我一直在尝试几个小时试图让这个工作,但我似乎无法做到。用户按下一个按钮,该按钮在HandlingPalettes中调用“newPalette”,然后推入SingleView。这里的所有revelant代码我有:在类之间传递NSMutableArray的问题
HandlingPalettes.h:
@interface HandlingPalettes : UIViewController {
NSMutableArray *navBarColour;
}
@property (nonatomic, retain) NSMutableArray *navBarColour;
-(void)newPalette;
@end
HandlingPalettes.m:
#import "HandlingPalettes.h"
#import "SingleView.h"
@implementation HandlingPalettes
@synthesize navBarColour;
-(void)newPalette {
UIColor *colourOfNavBar = [UIColor colorWithHue:0 saturation:0 brightness:0.25 alpha:1];
if (navBarColour == nil) {
navBarColour = [[NSMutableArray alloc] initWithObjects:colourOfNavBar, nil];
currentPalette = 0;
}
else {
[navBarColour addObject:colourOfNavBar];
currentPalette = navBarColour.count-1;
}
NSLog(@"Number: %i", navBarColour.count);
}
- (void)dealloc {
[super dealloc];
}
@end
SingleView.h:
#import "HandlingPalettes.h"
@interface SingleView : UIViewController {
}
HandlingPalettes *handlingPalettes;
@end
SingleView.m:
#import "SingleView.h"
@implementation SingleView
- (void)viewDidLoad {
handlingPalettes = [[HandlingPalettes alloc] init];
NSLog(@"Second number: %i", handlingPalettes.navBarColour.count);
[super viewDidLoad];
}
- (void)dealloc {
[handlingPalettes release];
[super dealloc];
}
@end
我的问题是,NSLog的返回:
数:1 第二个号码:0
然后再回到第一个视图,并再次按下按钮..
号码: 2 第二个号码:0
并再次..
数3: 二麻木呃:0
有人可以帮我解释为什么这不起作用吗?
非常感谢。
它应该怎么做? – Max 2011-03-09 04:00:15
为什么这是downvoted? – KingofBliss 2011-03-09 04:03:26
它应该传递数组,以便两个区域的计数相同。 – Andrew 2011-03-09 04:09:29