2017-07-30 35 views
0

我的问题很奇怪,所以我不能搜索它 我有一个模型的NSMutableArray对象属性改变它的类型和值误差

@implementation newChatMessage 

@synthesize miDProperty = _miDProperty; 
@synthesize mUserName = _mUserName; 
@synthesize mUID = _mUID; 
@synthesize mPhoto = _mPhoto; 
@synthesize mDate = _mDate; 
@synthesize mText = _mText; 
@synthesize SeenBy = _SeenBy; 
@end 



@interface newChatMessage : NSObject 

@property (nonatomic, assign) NSString *miDProperty; 
@property (nonatomic, strong) NSString *mDate; 
@property (nonatomic, strong) NSString *mText; 
@property (nonatomic, strong) NSString *mPhoto; 
@property (nonatomic, strong) NSString *mUID; 
@property (nonatomic, strong) NSString *mUserName; 
@property (nonatomic, strong) NSArray *SeenBy; 

@end 

然后我定义从数据从数据库火力地堡的未来对象

Allmessages = [[NSMutableArray alloc]init]; 
    ref = [[FIRDatabase database]reference]; 
    [[[ref child:@"classes"]child:_classname]observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) { 
     NSEnumerator *children = [snapshot children]; 

     printf("%s", snapshot.key); 
     FIRDataSnapshot *child; 
     while (child = [children nextObject]) { 
      NSDictionary *obj = (NSDictionary*)child.value; 
      newChatMessage* msg = [[newChatMessage alloc]init]; 
      //NSString *texte = [child ] 
      msg.miDProperty = [NSString stringWithFormat:@"%@",child.key];//here its run good 
      msg.mText = [obj objectForKey:@"mText"]; 
      msg.mDate = [obj objectForKey:@"mDate"]; 
      msg.mPhoto = [obj objectForKey:@"mPhoto"]; 
      msg.mUID = [obj objectForKey:@"mUID"]; 
      msg.mUserName = [obj objectForKey:@"mUserName"]; 
      msg.SeenBy = [obj objectForKey:@"SeenBy"]; 
      lastOne = child.key; 
      [Allmessages addObject:msg]; 
     } 
     [self.collectionView reloadData]; 
     if (lastOne != nil) 
      [self lesitner]; 
    }]; 

这项工作很好,所有的属性有它的正确值 但整理,并开始重新加载集合视图iDproperty后改变其价值和类型

- (UICollectionViewCell *)collectionView:(JSQMessagesCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    JSQMessagesCollectionViewCell *cell = [super collectionView:collectionView cellForItemAtIndexPath:indexPath];//here iDproperty type and value changes 
    newChatMessage* currentMSG = Allmessages[indexPath.row]; 
    NSLog(@"%ld", (long)indexPath.row); 
    NSLog(@"%ld", (long)indexPath.item); 
    [[[[[ref child:@"classes"]child:_classname]child:currentMSG.miDProperty]child:@"SeenBy"]setValue:[self senderId]]; 
    return cell; 
} 
+0

这是什么打印错误情况下的价值?你应该提出这个问题。 – adev

+0

对不起,我发现我的愚蠢的错误,这是因为我将IDproperty定义为“分配”,我必须使它“强”,但我不知道我必须做什么, 删除我的问题或答案它在这里 –

+0

如果答案对你有帮助,你可以回答并接受。 – adev

回答

0

我的问题是在定义nsstringassign althaugh它必须strong

@property (nonatomic, strong) NSString *miDProperty;