2011-01-27 92 views
0

我想在我的UIViewController中設置一個數組。筆尖被加載到我的應用程序,有時反覆。我將此添加到我的initWithNibName中以初始化陣列在initWithNibName中初始化一個數組

NSMutableArray *temp = [[NSMutableArray alloc] initWithObjects:@"one",@"two",@"three",@"four",@"five",nil]; 
    [self setScoreArray:temp]; 
    [temp release]; 

scoreArray是具有合成屬性的MutableArray。當我去訪問viewDidLoad中的數組時,我將[[self scoreArray] count]設置爲0.另外,當我重複加載筆尖時,出現訪問錯誤。有什麼建議麼?我錯過了一個步驟。謝謝。我合成屬性爲陣,在我的類聲明:

NSMutableArray *_scoreArray; 

然後

@property (nonatomic, retain) NSMutableArray *scoreArray; 
我在執行

@synthesize scoreArray =_scoreArray; 

,並在我的dealloc

然後

[_scoreArray release], _scoreArray = nil; 

我正在編輯這篇文章給s怎麼怎麼,我加載的筆尖與我的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是導致問題的原因之一。但它不是在加載時,而是在其他東西加載之後。我運行了分析器,它報告沒有內存泄漏。 順便說一句,currentVC是一個綜合性質。

+0

你如何聲明`scoreArray`屬性?你是否包含`retain`指令?否則我相信默認是`assign`。 – 2011-01-27 00:58:41

回答

3

你的UIViewController是如何創建的?如果它是通過另一個筆尖創建的,則-initWithNibName:bundle:不會被調用。相反,調用-initWithCoder:-awakeFromNib