2012-02-10 3 views
-1

두 가지보기가 있습니다. 첫 번째 것은 UITableView (프로그래밍 방식으로 생성)입니다. 두 번째 요소는 이미지가 포함 된 UIScrollView이고 그룹화 된 스타일은 UITableView입니다 (프로그래밍 방식으로도 생성 됨).내 스크롤을 스크롤 할 때 EXC_BAD_ACCESS

firstView -> secondView에서 탐색 할 때 모든 것이 올바르게 작동합니다. 그러나 firstView으로 돌아와서 firstView -> secondView를 두 번째로 탐색하려고하면 EXC_BAD_ACCESS 오류가 발생합니다.

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

    switch (section) { 
     case 0: 

     //header - breve descrizione 
     return 2; 

     break; 
    case 1: //mappa 

     //header - mappa statica (immagine) - footer (indirizzo) 
     return 3; 

     break; 
    case 2: //review 

     //header - prima review 
     return 2; 

     break; 
    default: 
     return 0; 

     break; 


} 

} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 

    switch (indexPath.section) { 
     case 0: 
      switch (indexPath.row) { 
       case 0: //case titolo (header) 


    return HTABLE_DESCR_HEADER; 
        break; 

       case 1: //case corpo 
        return HTABLE_DESCR_BODY; 
        break; 

       default: 
        return 0; 
        break; 
      } 
      break; 
     case 1: 

      switch (indexPath.row) { 
       case 0: //case titolo (header) 
        return HTABLE_LOC_HEADER; 
        break; 

       case 1: //case corpo 
        return HTABLE_LOC_BODY; 
        break; 

       case 2: //case footer 
        return HTABLE_LOC_FOOTER; 
        break; 

       default: 
        return 0; 
        break; 
      } 

      break; 
     case 2: 

      switch (indexPath.row) { 
       case 0: //case titolo (header) 
        return HTABLE_REV_HEADER; 
        break; 

       case 1: //case corpo 
        return HTABLE_REV_BODY; 
        break; 

       default: 
        return 0; 
        break; 
      } 

      break; 
     default:    
      return 0; 
      break; 
    } 

} 

/*- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 

return @"Travellers Guide"; 

}*/ 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    int section = 2; 

    //se ci sono review 
    if ([[[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:@"list_review"] count] > 0) { 
     section++; 
    } 

    return section; 

} 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     cell = [self getCellContentView:CellIdentifier]; 
    }  

    cell.accessoryType = UITableViewCellAccessoryNone; 

    cell.selectionStyle = UITableViewCellSelectionStyleGray; 

    switch (indexPath.section) { 
     case 0: //descrizione 

      switch (indexPath.row) { 
       case 0: //header 

        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"language"] isEqualToString:@"it"]) { 
         cell.textLabel.text = @"Descrizione"; 
        } else { 
         cell.textLabel.text = @"Description"; 
        } 
        cell.textLabel.backgroundColor = [UIColor clearColor]; 
        cell.textLabel.textColor = [UIColor blackColor]; 
        cell.textLabel.shadowColor = [UIColor whiteColor]; 
        cell.textLabel.shadowOffset = CGSizeMake(1, 1); 
        cell.textLabel.highlightedTextColor = [UIColor blackColor]; 
        cell.textLabel.font = [UIFont boldSystemFontOfSize:11.0]; 
        cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"rigaDescrHeader.png"]]; 

        break; 

       case 1: //descrizione 

        NSLog(@"Descr"); 

        cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"rigaRevBody.png"]]; 
        cell.textLabel.text = [[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:@"description"]; 
        cell.textLabel.font = [UIFont systemFontOfSize:10.0]; 
        cell.textLabel.lineBreakMode = UILineBreakModeTailTruncation; 
        cell.textLabel.numberOfLines = 3; 
        cell.textLabel.textColor = [UIColor blackColor]; 
        cell.textLabel.backgroundColor = [UIColor clearColor]; 
        cell.textLabel.shadowColor = [UIColor whiteColor]; 
        cell.textLabel.shadowOffset =CGSizeMake(1, 1); 
        cell.textLabel.highlightedTextColor = [UIColor blackColor]; 

        break; 

       default: 
        break; 
      } 

      break; 
     case 1: //mappa 

      //header - mappa statica (immagine) - footer (indirizzo) 
      switch (indexPath.row) { 
       case 0: //header 

        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"language"] isEqualToString:@"it"]) { 
         cell.textLabel.text = @"Posizione"; 
        } else { 
         cell.textLabel.text = @"Location"; 
        } 
        cell.textLabel.font = [UIFont boldSystemFontOfSize:11.0]; 
        cell.textLabel.backgroundColor = [UIColor clearColor]; 
        cell.textLabel.textColor = [UIColor blackColor]; 
        cell.textLabel.shadowColor = [UIColor whiteColor]; 
        cell.textLabel.shadowOffset = CGSizeMake(1, 1); 
        cell.textLabel.highlightedTextColor = [UIColor blackColor]; 
        cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"rigaLocHeader.png"]]; 

        break; 

       case 1: //mappa 

        NSLog(@"Mappa"); 

        CLLocationDegrees latitude = [[[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:@"latitude"] doubleValue]; 
        CLLocationDegrees longitude = [[[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:@"longitude"] doubleValue]; 
        CLLocation* poiLocation = [[[CLLocation alloc] initWithLatitude:latitude longitude:longitude] autorelease]; 
        Annotation *ann = [Annotation annotationWithCoordinate:poiLocation.coordinate]; 
        //mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, HTABLE_LOC_BODY)]; 
        [mapView setHidden:NO]; 
        [mapView addAnnotation:ann]; 
        MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}}; 
        region.center = poiLocation.coordinate;      
        region.span.longitudeDelta = 0.05f; 
        region.span.latitudeDelta = 0.05f; 
        [self.mapView setRegion:region animated:YES]; 
        [self.mapView regionThatFits:region]; 
        cell.backgroundView = mapView; 


        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 302, 120)]; 
        imgView.image = [UIImage imageNamed:@"ombraMappa.png"]; 
        [cell.backgroundView addSubview:imgView]; 
        [imgView release]; 

        break; 

       case 2: //footer 

        cell.textLabel.text = [[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:@"locality"]; 
        cell.textLabel.font =[UIFont systemFontOfSize:10.0]; 
        cell.textLabel.backgroundColor = [UIColor clearColor]; 
        cell.textLabel.textColor = [UIColor blackColor]; 
        cell.textLabel.shadowColor = [UIColor whiteColor]; 
        cell.textLabel.shadowOffset = CGSizeMake(1, 1); 
        cell.textLabel.highlightedTextColor = [UIColor blackColor]; 

        cell.detailTextLabel.text = [[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:@"address"]; 
        cell.detailTextLabel.font = [UIFont boldSystemFontOfSize:9.0]; 
        cell.detailTextLabel.textColor = [UIColor grayColor]; 
        cell.detailTextLabel.backgroundColor = [UIColor clearColor]; 
        cell.detailTextLabel.shadowColor = [UIColor whiteColor]; 
        cell.detailTextLabel.shadowOffset = CGSizeMake(1, 1); 
        cell.detailTextLabel.highlightedTextColor = [UIColor blackColor]; 
        cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"rigaLocFooter.png"]]; 

        break; 

       default: 
        break; 
      } 

      break; 
     case 2: //review 

      //header - mappa statica (immagine) - footer (indirizzo) 
      switch (indexPath.row) { 
       case 0: //header 

        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"language"] isEqualToString:@"it"]) { 
         cell.textLabel.text = [NSString stringWithFormat:@"Recensioni (%d)",[[[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:@"list_review"] count]]; 
        } else { 
         cell.textLabel.text = [NSString stringWithFormat:@"Review (%d)",[[[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:@"list_review"] count]]; 
        } 
        cell.textLabel.font = [UIFont boldSystemFontOfSize:11.0]; 
        cell.textLabel.backgroundColor = [UIColor clearColor]; 
        cell.textLabel.textColor = [UIColor blackColor]; 
        cell.textLabel.shadowColor = [UIColor whiteColor]; 
        cell.textLabel.shadowOffset = CGSizeMake(1, 1); 
        cell.textLabel.highlightedTextColor = [UIColor blackColor]; 

        cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"rigaLocHeader.png"]]; 

        break; 

       case 1: //review 

        cell.textLabel.text = [[[[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:@"list_review"] objectAtIndex:0] objectForKey:@"review"]; 
        cell.textLabel.font =[UIFont systemFontOfSize:10.0]; 
        cell.textLabel.lineBreakMode = UILineBreakModeTailTruncation; 
        cell.textLabel.numberOfLines = 3; 
        cell.textLabel.backgroundColor = [UIColor clearColor]; 
        cell.textLabel.textColor = [UIColor blackColor]; 
        cell.textLabel.shadowColor = [UIColor whiteColor]; 
        cell.textLabel.shadowOffset = CGSizeMake(1, 1); 
        cell.textLabel.highlightedTextColor = [UIColor blackColor]; 
        cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"rigaRevBody.png"]]; 

        break; 

       default: 
        break; 
      } 

      break; 
     default:     
      break; 
    } 

    return cell; 

} 


- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier { 

    UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease]; 

    return cell; 
} 
+3

대니는 .. EXC_BAD_ACCESS 검색하거나 오른쪽 열에서 관련 링크 중 하나를 클릭하십시오.이것을 디버깅하는 방법이 있습니다 (힌트 : 좀비). 나는 너 자신이이 문제를 해결할 수있을 것이라고 확신한다. 플러스 아무도 코드없이 도울 수있을 것이다. – Joe

+0

코드를 볼 필요가 있거나 ARC를 사용하고 있습니까? – GregularExpressions

+0

할당 된 모든 객체에 릴리스가 전송됩니까? 할당되지 않은 객체에 액세스하려고하는 것 같습니다. – LightNight

답변

1

이 다음에 하나의 뷰의 진행에 의해 발생되지 않습니다

UPDATE

이것은 secondView에서 UITableView 대표의 코드입니다. 오히려, 그것은 뷰의 속성이거나, 뷰 객체 자체의 생성 및 해제 (또는 아닌) 일 것입니다.

첫 번째 단계는 분석기를 실행하는 것입니다. 그런 다음 모든 문제를 해결하고 여전히 문제가 발생하면 계측기에서 누수 도구를 실행하십시오.

finding reason for EXC_BAD_ACCESS - in Xcode4

:

해결하는 방법에 대한 단계 지침에 의해 이러한 오류 단계를 원인이 무엇에 우수한 링크와 함께 EXC_BAD_ACCESS 문제 해결에 대한 자세한 내용은

,이 질문에 대한 답을 살펴 가지고 귀하의 경우에는 Random EXC_BAD_ACCESS in a place that it cannot happen

, 내가 특별히 당신이 secondView를 작성하는 방법을보고 싶은데, 당신은 secondView로 돌아 가면 당신은 firstView와 함께 무엇을.

+0

올바른 오류 메시지와 다른 오류 메시지로 편집 한 이유는 무엇입니까? – Diziet

+0

dunno. 그것은 흔한 실수입니다. 나는 단지 그것을 고쳤다. –

+0

기괴함. 그리고 꽤 큰 기여자로부터. – Diziet

1

ARC로 변환하기 전에 문제가되었던 큰 응용 프로그램에서 EXC_BAD_ACCESS 문제를 추적하는 데 일주일이 걸렸습니다. 나는 "switch"구조의 닫기 괄호에 EXC_BAD_ACCESS을 얻을 것이다. 그러나 NSZombieEnabled과 다양한 악기 설정은 나를 위해 아무 것도 탐지하지 못합니다.

차이점을 만든 케이스 주위에 중괄호를 달았습니다.

case ...:{ 
stmt; 
stmt; 
}break; 

이 큰 내 두 곳에서 문제를 해결 :

case ...: 
stmt; 
stmt; 
break; 

후 : 아마도 그것은 일부에 대한 중요한 이었지만 나는

전에 즉, 그들 각각을 위해 그것을했다 나를위한 앱. 나는 ARC와 switch/case에 대한 어딘가의 것을 읽었다는 것을 안다.하지만 어째서 이런 일이 일어 났고 왜이 수정이 효과가 있었는지에 대한 이론을 이해하지 못한다. 아마도 누군가가 설명 할 수 있습니다. (나중에 : openradar에서 다음 참조를 읽은 후에 모두 이해가됩니다. case 문 사이에 생성 된 "정리 코드"에 잘못된 것이 있습니다. 가짜 "release"가 생성되고 곧 EXC_BAD_ACCESS이 발생합니다.)

는 또한 관련 될 수있는이 발견 : http://openradar.appspot.com/11329693

관련 문제