我正在尝试在我的UIViewController中设置一个数组。笔尖有时会反复加载到我的应用程序中。我将此添加到我的initWithNibName以初始化数组
NSMutableArray *temp = [[NSMutableArray alloc] initWithObjects:@"one",@"two",@"three",@"four",@"five",nil];
[self setScoreArray:temp];
[temp release];
scoreArray是具有合成属性的MutableArray。当我在viewDidLoad中访问数组时,我得到[[self scoreArray] count]为0.此外,当我反复加载nib时,我得到一个错误的访问错误。有什么建议?我错过了一步。谢谢。我在我的类声明中合成了数组的属性:
NSMutableArray *_scoreArray;
然后
@property (nonatomic, retain) NSMutableArray *scoreArray;
然后在我的实现中
@synthesize scoreArray =_scoreArray;
和我的dealloc
[_scoreArray release], _scoreArray = nil;
我正在编辑这篇文章,以展示我是如何用我的RootViewController加载笔尖的
- (void) createNewSlide:(NSInteger)slideIndex {
NSDictionary *slideObj = (NSDictionary *)[[self slidesDataSource] objectAtIndex:slideIndex - 1];
NSString *currentTitle = [slideObj objectForKey:@"title"];
[[self slideTitle] setText:currentTitle];
NSString *currentContent = [slideObj objectForKey:@"contentString"];
NSString *currentContentType = [slideObj objectForKey:@"contentType"];
if ([self currentVC] != nil) {
[[self currentVC] reset];
[self setCurrentVC:nil];
}
if ([currentContentType isEqualToString:@"slide"])
{
[[self containerViewController] loadImage:currentContent];
}
else if ([currentContentType isEqualToString:@"quiz"])
{
NSInteger quizNum = [[slideObj objectForKey:@"quizNum"] integerValue];
NSLog(@"%s%@%d",__FUNCTION__,@"quizNum ",quizNum);
QuizViewController *quizView = [[QuizViewController alloc] initWithNibName:@"QuizViewController" bundle:nil];
[self setCurrentVC:quizView];
[quizView release];
[[self containerViewController] replaceSlideWithViewController:[self currentVC]];
}
else if ([currentContentType isEqualToString:@"PIDView"])
{
PIDViewController *PIDView = [[PIDViewController alloc] initWithNibName:@"PIDView" bundle:nil];
[self setCurrentVC:PIDView];
[PIDView release];
[[self containerViewController] replaceSlideWithViewController:[self currentVC]];
}
else if ([currentContentType isEqualToString:@"LoginView"])
{
LoginViewController *login = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil];
[self setCurrentVC:login];
[login release];
[[self containerViewController] replaceSlideWithViewController:[self currentVC]];
}
else if ([currentContentType isEqualToString:@"VakView"])
{
VakViewController *vakView = [[VakViewController alloc] initWithNibName:@"VakView" bundle:nil];
[self setCurrentVC:vakView];
[vakView release];
[[self containerViewController] replaceSlideWithViewController:[self currentVC]];
}
else if ([currentContentType isEqualToString:@"PlanView"])
{
PlanViewController *planView = [[PlanViewController alloc] initWithNibName:@"PlanView" bundle:nil];
[self setCurrentVC:planView];
[planView release];
[[self containerViewController] replaceSlideWithViewController:[self currentVC]];
}
感谢您的见解。 PlanView是导致问题的原因。但它不是在加载时,而是在它之后加载其他东西的时候。我运行了分析仪,它报告没有内存泄漏。 BTW,currentVC是一个综合属性。
答案 0 :(得分:3)
你的UIViewController是如何创建的?如果它是通过另一个笔尖创建的,则-initWithNibName:bundle:
不会被调用。而是调用-initWithCoder:
和-awakeFromNib
。