【发布时间】:2017-01-07 19:58:40
【问题描述】:
我正在创建聊天应用程序,我向arrayChat 添加消息:
-(void)msgRecevied:(NSMutableDictionary *)messageContent
{
NSString *m = [messageContent objectForKey:kMsg];
[messageContent setObject:[m substituteEmoticons] forKey:kMsg];
self.arrayTemp = messageContent;
[self.arrayChat addObject:self.arrayTemp];
[_tblChat reloadData];
if(self.arrayChat.count > 1){
NSIndexPath *topIndexPath = [NSIndexPath indexPathForRow:self.arrayChat.count-1
inSection:0];
[self.tblChat scrollToRowAtIndexPath:topIndexPath
atScrollPosition:UITableViewScrollPositionMiddle
animated:YES];
}
}
但是一段时间后,当我将设备放置一段时间后,当我发送消息后,它会将对象添加到 arrayChat,但它没有加载到 tableView 中,我重新加载表,它显示了它从 @ 丢失的最后一个对象987654324@.
我声明arrayChat 喜欢:
@interface ViewController : UIViewController
{
NSMutableArray *arrayChat;
}
@property (strong,nonatomic) NSMutableArray *arrayChat;
我也是@synthesize arrayTemp;
这里有什么错误吗?
编辑
我将我的 arrayChat 添加到其他类,并将该类声明为 Appdelegate 我使用该类访问应用程序上的该数组,它正在工作,但是当我将对象添加到数组但它没有重新加载我的数组时出现问题表一次,我正在放大按钮上的聊天视图,显示我最后一次添加到数组的对象。
这是我放大视图时的代码:
-(IBAction)onClickViewLarge:(id)sender{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
if (!isShow) {
[_btnOpen setImage:[UIImage imageNamed:@"ico_expand"] forState:UIControlStateNormal];
[UIView animateWithDuration:0.5 animations:^{
if(screenHeight >= 736)
self.view.frame = CGRectMake(0,66 , screenWidth, screenHeight - 66);
else if (screenHeight >= 667)
self.view.frame = CGRectMake(0,60 , screenWidth, screenHeight - 60);
else if (screenHeight >= 568)
self.view.frame = CGRectMake(0,51 , screenWidth, screenHeight - 51);
else if (screenHeight >= 480)
self.view.frame = CGRectMake(0,43 , screenWidth, screenHeight - 43);
}];
isShow = true;
} else {
[_btnOpen setImage:[UIImage imageNamed:@"ico_open"] forState:UIControlStateNormal];
[UIView animateWithDuration:0.5 animations:^{
self.view.frame = CGRectMake(screenWidth - 250,screenHeight - 450 , 250, 450);
}];
isShow = false;
}
if([app.Glb.arrayChat count] > 0)
{
[self.tblChat reloadData];
NSIndexPath *topIndexPath = [NSIndexPath indexPathForRow:app.Glb.arrayChat.count-1
inSection:0];
[self.tblChat scrollToRowAtIndexPath:topIndexPath
atScrollPosition:UITableViewScrollPositionMiddle
animated:YES];
}
}
这是怎么解决的?
【问题讨论】:
-
我认为问题出在全局 arrayTemp 对象上。尝试在你的 msgRecevied 方法中声明它
-
没有任何影响。
-
你的arrayTemp也强吗?如果不设置为强。我认为一段时间后它的设置为零。
-
是的,它的 :strong,nonatomic
-
你初始化你的
self.arrayChat了吗?
标签: ios objective-c nsmutablearray xmpp openfire