2015-01-12 48 views
-3

我做了一個uitableview單元格來顯示註釋,並且這個單元格包含一個新的tableview來顯示子註釋。通常它工作正常,但有時它會突然崩潰,報告[NSUITableViewCellAccessibilityElement superview]無法識別的選擇器實例。我花了很多時間,但無法修復它。我甚至不知道什麼時候會發生這種事故。任何人都可以回答我的問題,thx!自定義uitableview崩潰報告NSuitableviewcellAccessbilityElement超級查看]無法識別的選擇器實例

#import "HMCommentCell.h" 
#import "HMHttpUtil.h" 
#import "HMCommonUtil.h" 
#import "HMSubcommentCell.h" 
static NSString *cellForSubcomment = @"cellForSubcomment"; 
static NSString *subcommentCellnib = @"HMSubcommentCell"; 

@interface HMCommentCell()<UITableViewDataSource, UITableViewDelegate,  HMSubcommentCellDelegate> 


@end 
@implementation HMCommentCell 

- (void)awakeFromNib { 
    // Initialization code 
    [self setSelectionStyle:UITableViewCellSelectionStyleNone]; 
    [HMCommonUtil setupTitleTextView:_titleTextView]; 
    [HMCommonUtil setupTextView:_contentTextView]; 

    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, 1)]; 
     headerView.backgroundColor = [UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:100.0/100.0]; 

     [_subCommentsView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; 
     _subCommentsView.scrollEnabled = NO; 
     _subCommentsView.delegate = self; 
     _subCommentsView.dataSource = self; 
     _subCommentsView.tableHeaderView = headerView; 
     _subCommentsView.tableFooterView = nil; 

     [_subCommentsView registerNib:[UINib nibWithNibName:subcommentCellnib bundle:nil] forCellReuseIdentifier:cellForSubcomment]; 


    } 

    - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 
     [super setSelected:selected animated:animated]; 

     // Configure the view for the selected state 
    } 

    - (void)setSingleComment:(HMCommentEntity *)singleComment{ 
     _singleComment = singleComment; 
     //[_subCommentsView reloadData]; 
    } 

    - (void)SetupWithCommentEntity:(HMCommentEntity *)commentEntity{ 
     _userAvatarImageView.image = [UIImage imageNamed:@"MembersIcon"]; 
     if(commentEntity.creator.is_post_creator){ 
      _userAvatarImageView.backgroundColor = [UIColor colorWithRed:254.0/255.0 green:177.0/255.0 blue:45.0/255.0 alpha:100.0/100.0]; 
      [_authorLable setHidden:NO]; 
     }else{ 
      _userAvatarImageView.backgroundColor = [UIColor clearColor]; 
      [_authorLable setHidden:YES]; 
     } 
     [HMHttpUtil asyncLoadImage:commentEntity.creator.avatar 
          success:^(UIImage *image) { 
           _userAvatarImageView.image = image; 
          } fail:^(NSError *error) { 
           NSLog(@"讀取用戶頭像失敗 %@", [error description]); 

          }]; 
     [HMHttpUtil asyncLoadImage:commentEntity.image_info.image_url 
          success:^(UIImage *image) { 
           _slideImageView.image = image; 
          } fail:^(NSError *error) { 
           NSLog(@"讀取評論圖片失敗 %@", [error description]); 
          }]; 
     //NSLog(@"the reply_to_id of this comment is %@", commentEntity.reply_to_id); 
     _titleTextView.text = commentEntity.commentCellTitle; 
     _contentTextView.text = commentEntity.content; 
     _timeLable.text = commentEntity.time; 
     _singleComment = commentEntity; 
     if([_singleComment.children count] == 0){ 
      _subCommentsView.hidden = YES; 
     }else{ 
      _subCommentsView.hidden = NO; 
      [self AdjustHeightOfContent:commentEntity]; 
      [self AdjustHeightOfSubcomments:commentEntity]; 
     } 
     //[_replyButton setTitle:@"Reply" forState:UIControlStateNormal]; 

     [_subCommentsView reloadData]; 

    } 

    #pragma mark - tableview datasource 
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 
     return 1; 
    } 

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
     return [_singleComment.children count] > 0? [_singleComment.children count]:0; 
    } 

    - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
     HMSubcommentCell *cell = [tableView dequeueReusableCellWithIdentifier:cellForSubcomment]; 
     cell.commentEntity = [_singleComment.children objectAtIndex:indexPath.row]; 
     cell.delegate = self; 
     return cell; 
    } 

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 
     return ((HMCommentEntity*)[_singleComment.children objectAtIndex:indexPath.row]).contentHeight; 
    } 


    #pragma mark - adjust the cell layout 
    - (void)AdjustHeightOfContent:(HMCommentEntity*)commentEntity{ 
     CGRect contentFrame = _contentTextView.frame; 
     contentFrame.size.height = commentEntity.contentHeight; 
     [_contentTextView setFrame:contentFrame]; 
    } 

    - (void)AdjustHeightOfSubcomments:(HMCommentEntity*)commentEntity{ 
     if(commentEntity.subCommentHeight > 0){ 
      CGRect subtableFrame = _subCommentsView.frame; 
      float gap = commentEntity.subCommentHeight - subtableFrame.size.height; 
      subtableFrame.size.height = commentEntity.subCommentHeight; 
      subtableFrame.origin.y = subtableFrame.origin.y - gap; 
      [_subCommentsView setFrame:subtableFrame]; 
     } 
    } 

    #pragma mark - reply function 
    - (IBAction)ReplyFromCell:(id)sender { 
     //[_delegate onReplyWithCommentEntity:_singleComment replyid:_singleComment.reply_to_id mark:_singleComment.mark]; 
     [self ArouseReplyFunction:_singleComment]; 
     // NSLog(@"Reply button reacts"); 
    } 

    - (IBAction)IntoCommenterInfo:(id)sender { 
    } 

    - (IBAction)IntoBigImage:(id)sender { 
     if(_bigImageBoard){ 
      [_bigImageBoard ShowBigImageUsingANewVC:_singleComment.image_info.image_big_url]; 
     } 
    } 

    - (void)SubcommentCellOnReplyWithCommentEntity:(HMCommentEntity *)commentEntity{ 
     [self ArouseReplyFunction:commentEntity]; 
    } 

    - (void)ArouseReplyFunction:(HMCommentEntity*)commentEntity{ 
     if(_delegate != nil){ 
      [_delegate CommentCellOnReplyWithCommentEntity:commentEntity commentIndex:_indexrow]; 
     }else{ 
      NSLog(@"commentcell delegate 爲空"); 
     } 
    } 
    @end 
+0

你能提供你的代碼嗎? – CephBirk

+1

顯示你調用superview的代碼 - 即拋出異常的代碼 – Paulw11

+0

@ Paulw11我從來沒有在代碼中調用superview,並且異常是從內存中拋出的。這麼奇怪 – Rabiiit

回答

0

我不知道這裏發生了什麼。但我很確定問題是由單元格中的tableview造成的。我不知道是否會有人發現這個問題。我不得不說,將可滾動控制器嵌入可滾動控制器是危險的。我已經適應了一種正常的方式。

相關問題