我创建了一个uitableview单元格来显示注释,此单元格包含一个新的tableview来显示子注释。通常它工作正常,但有时它会突然崩溃,报告[NSUITableViewCellAccessibilityElement superview]无法识别的选择器到实例。我花了很多时间但无法修复它。我甚至不知道这次崩溃何时会发生。任何人都可以回答我的问题,谢谢!!!
#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 :(得分:0)
我不知道这里发生了什么。但我很确定问题是由单元格中的tableview引起的。我不知道是否会有人发现这个问题。我不得不说在可滚动的控制器中嵌入可滚动控制器是危险的。我已经采用了正常的方式。