2012-02-10 72 views
-1

我有兩個視圖:第一個是UITableView以普通樣式(以編程方式創建);第二個是UIScrollView,其中包含圖像和分組樣式的UITableView(也是以編程方式創建的)。EXC_BAD_ACCESS當我滾動我的視圖

當我從firstView - > secondView導航一切正常。但是,如果我回到firstView,然後嘗試第二次導航firstView - > secondView,則會出現EXC_BAD_ACCESS錯誤。

UPDATE

這是UITableView代表在secondView的代碼:

- 
(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 2012-02-10 18:20:23

+0

我們需要查看您的代碼,您是否還在使用ARC? – GregularExpressions 2012-02-10 18:20:34

+0

您是否將版本發送給所有分配的對象?看來你試圖訪問釋放對象.. – LightNight 2012-02-10 18:29:15

回答

1

EXC_BAD_ACCESS不是由一個視圖到下一的進展引起的。相反,它將成爲那些觀點的屬性,或者是創造和釋放(或不是)視角對象本身的責任。

您的第一步是運行分析儀。然後,如果您已經修復了所有這些問題,並且仍然存在問題,請開始在樂器中運行「泄漏」工具。

有關解決EXC_BAD_ACCESS問題,有什麼原因導致這些錯誤,並步步爲如何解決逐步說明優秀的鏈接以及更多的細節,看看這些問題的答案:

finding reason for EXC_BAD_ACCESS - in Xcode4

Random EXC_BAD_ACCESS in a place that it cannot happen

在你的情況,我會專門看你如何創建secondView,和你firstView做什麼,當你回到secondView

+0

爲什麼編輯這個錯誤信息是錯誤的? – Diziet 2012-02-14 15:19:35

+0

dunno。這是一個常見的錯誤。我剛修好了。 – 2012-02-14 15:46:09

+0

古怪。並從一個非常大的SO貢獻者。 – Diziet 2012-02-15 11:34:39

1

我剛剛花了一個星期的時間跟蹤了一個大型應用程序中的EXC_BAD_ACCESS問題,該應用程序在將其轉換爲ARC之前工作正常。我會在「switch」結構的右括號上得到EXC_BAD_ACCESS。然而NSZombieEnabled和各種樂器設置不會爲我檢測到任何東西。

這是什麼修正它把案件的捲毛放在了不同的地方。我這樣做是爲他們每個人,雖然也許它是隻有一些關鍵的,即

前:

case ...: 
stmt; 
stmt; 
break; 

後:

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

這兩個地方的固定內的大問題應用程序爲我。我知道我讀了關於ARC和switch/case的一些東西(也許有人可以添加一個鏈接),但我不明白爲什麼會發生這種情況,以及爲什麼這個修復工作。也許有人可以解釋。 (稍後:在閱讀openradar中的以下參考資料之後,這一切都是有道理的 - 在case語句之間生成的「清除代碼」中存在錯誤---生成了一個假「釋放」並且很快會導致EXC_BAD_ACCESS。)

我也發現了這一點,這可能與:http://openradar.appspot.com/11329693

相關問題