#pragma mark - createDataSource
-(NSMutableArray*)dataSource
{
if (_dataSource == nil) {
_dataSource = [NSMutableArray array];
}
return _dataSource;
}
#pragma mark - createTableView
-(UITableView *)tableView
{
if (!_tableView) {
CGRect rect =self.view.frame;
_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(rect), CGRectGetHeight(rect)-64 - self.chatToolBar.frame.size.height) style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor clearColor];
_tableView.tableFooterView = [[UIView alloc]init];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = .5;
//_tableView.backgroundColor = [UIColor blackColor];
//self.view.backgroundColor = [UIColor redColor];
//_chatToolBar.alpha = 0;
//[_tableView addGestureRecognizer:lpgr];
//_tableView.bounces = NO;
}
return _tableView;
}
#pragma mark - dealloc in CurrentViewController
-(void)dealloc //it be called when I use it's navigation pop back.
{
_tableView.delegate = nil;
_tableView.dataSource = nil;
_tableView = nil;
_slimeView.delegate = nil;
_slimeView = nil;
_chatToolBar.delegate = nil;
_chatToolBar = nil;
//清除当前聊天的用户
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
appDelegate.currentChattingName = nil;
[[EaseMob sharedInstance].chatManager stopPlayingAudio];
[[NSNotificationCenter defaultCenter]removeObserver:self];
[[EaseMob sharedInstance].chatManager removeDelegate:self];
[[[EaseMob sharedInstance] deviceManager]removeDelegate:self];
[[NSNotificationCenter defaultCenter]removeObserver:self name:@"kDXNotificationHeadImagePressed" object:nil];
[[NSNotificationCenter defaultCenter]removeObserver:self name:kNOTIFICATION_REFRESHBACKBTNUNREADMESSAGECOUNT object:nil];
[[NSNotificationCenter defaultCenter]removeObserver:self name:kNOTIFICATION_CHATVIEW_SAVE_MESSAGECOUNT object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:LONGPRESSTEXTNOTIFICATION object:nil];
}
#pragma mark - When I use block
-(void)addChatDataToMessage:(EMMessage*)message
{
__weak ChatViewController *weakSelf = self; // sometimes I like use __weak typeof(self) weakSelf = self; Is there have problem due to I use self.dataSource and self.tableView?
dispatch_async(_messageQueue, ^{
NSArray *messages = [weakSelf addChatToMessage:message];
NSMutableArray *indexPaths = [[NSMutableArray alloc]init];
for (int i = 0; i<messages.count; i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(weakSelf.dataSource.count + i) inSection:0];
[indexPaths addObject:indexPath];
}
dispatch_async(dispatch_get_main_queue(), ^{
//[weakSelf.tableView beginUpdates];
[weakSelf.dataSource addObjectsFromArray:messages];
[weakSelf.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
//[weakSelf.tableView endUpdates];
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.tableView scrollToRowAtIndexPath:[indexPaths lastObject] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
[weakSelf.tableView reloadData];
});
});
});
//[self scrollViewToBottom:YES];
}
是否有问题我覆盖了self.tableView?我使用弱自我的块。我找不到我的地方我的细胞不能dealloc。我的细胞也没有使用方案。谢谢你的阅读。
答案 0 :(得分:0)
你可以运行静态分析仪吗?你也可以粘贴表视图单元格代码吗?您可能正在保留周期中捕获tableViewCell。没有tableViewCell代码很难分辨。