2012-02-10 69 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

相关问题