2017-07-30 69 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;