修复了数组可能越界的问题

This commit is contained in:
fengshuo
2022-11-11 17:46:37 +08:00
parent e855f87849
commit c22ede0a13
146 changed files with 515 additions and 371 deletions

View File

@@ -16,6 +16,7 @@
#import "XPMacro.h"
#import "UITableView+NIMScrollToBottom.h"
#import "ThemeColor.h"
#import "NSArray+Safe.h"
///Model
#import "RoomInfoModel.h"
#import "UserInfoModel.h"
@@ -115,7 +116,7 @@
[self.sessionTableView.mj_header endRefreshing];
if (error == nil && messages.count > 0) {
for (int i = ((int)messages.count -1); i > 0; i--) {
NIMMessage * message = [messages objectAtIndex:i];
NIMMessage * message = [messages safeObjectAtIndex1:i];
[self.messages insertObject:message atIndex:0];
}
}
@@ -350,7 +351,7 @@
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
NIMMessage * message = [self.messages objectAtIndex:indexPath.row];
NIMMessage * message = [self.messages safeObjectAtIndex1:indexPath.row];
NSString * identifier = [MessageCell cellContent:message];
///cell
MessageCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
@@ -361,12 +362,12 @@
cell = [tableView dequeueReusableCellWithIdentifier:identifier];
}
cell.delegate = self;
[cell renderWithMessage:[self.messages objectAtIndex:indexPath.row]];
[cell renderWithMessage:[self.messages safeObjectAtIndex1:indexPath.row]];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NIMMessage *msg = [self.messages objectAtIndex:indexPath.row];
NIMMessage *msg = [self.messages safeObjectAtIndex1:indexPath.row];
return [MessageCell measureHeight:msg];
}
@@ -498,7 +499,7 @@
UIWindow * currentWindow;
for (int i = 0; i < [UIApplication sharedApplication].windows.count; i++) {
UIWindow * window = [[UIApplication sharedApplication].windows objectAtIndex:i];
UIWindow * window = [[UIApplication sharedApplication].windows safeObjectAtIndex1:i];
if(window.tag == 1000) {
currentWindow = window;
break;