2011-08-12 2 views
1

내있는 NSMutableArray가 해제 될 것으로 보인다되고, 여기에 내 코드 어디 있는지 알아낼 수 없습니다 :왜 jQuery과 내있는 NSMutableArray의 할당 해제는

- (void)awakeFromNib { 

arrayOfData = [[NSMutableArray alloc] initWithCapacity:0]; 
[arrayOfData addObject:@"test"]; 

NSLog(@"array: %@", arrayOfData); 

} 

모든 잘 여기!

그런 다음 UITable을 만들고 뷰에 추가 한 다음 일부 데이터를 요청합니다. 모든 것이 정상입니다. 행의 수를 생성

 arrayOfData = [response objectForKey:@"results"]; 
     NSLog(@"count: %i", [arrayOfData count]); 
     NSLog(@"success!"); 
     numberOfRows = [arrayOfData count]; 
     [self.myTableView reloadData]; 

잘 너무 작동합니다

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

NSLog(@"test: %i", numberOfRows); 
return numberOfRows; 

} 

지금 내 배열은 그 라인에서 "할당이 해제 된 인스턴스에 보낸 메시지"를 얻는다 접근.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *MyIdentifier = @"MyIdentifier"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

if (cell == nil) 
{ 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
            reuseIdentifier:MyIdentifier] autorelease]; 
} 


    // crashes here! 
NSLog(@"array: %i", [arrayOfData count]); 

if (numberOfRows){ 

    NSString *filename = [[arrayOfData objectAtIndex:indexPath.row] objectForKey:@"filename"]; 
    NSString *url = [NSString stringWithFormat: @"http://www.web.com/dir/%@", filename]; 
    [cell.imageView setImageWithURL:[NSURL URLWithString:url] 
        placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; 

    cell.textLabel.text = @"My Text"; 
} 

return cell; 

} 내가 어떤 도움을 주시면 감사하겠습니다 한도 내 헤더이 있고, 나뿐만 아니라

@property (nonatomic, retain) NSMutableArray *arrayOfData; 

을 @synthesize 사용

! 이 라인 arrayOfData을 재 할당하는 것처럼

답변

1

것 같습니다 :

arrayOfData = [response objectForKey:@"results"]; 

을 만약 당신이 원하는 않으면 다음을 시도

arrayOfData = [[response objectForKey:@"results"] retain]; 
+0

아, 그래 그게 문제였다. 제 질문은, 제가 재 할당 할 때, 왜 풀어 줄까요? "Response"가 할당 해제되면 해제됩니까? –

+0

그 한 가지 가능성이 있습니다. 나는이 클래스가 무엇을하는지 모르지만 [response objectForKey : @ "results"]가 자동 렌더링 된 객체를 반환 할 수도 있습니다. – paulmelnikow

+0

당신은 내 하루를 보냈습니다. :) 이제 배열을 유지하거나 호출하는 것이 더 나은지 알고 싶습니다. 'arrayOfData = [NSMutableArray initWithArray : [response objectForKey : @ "results"]]]; – Maverick1st