我的问题非常奇怪,所以我无法搜索它 我有一个模特
@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
然后我根据来自fireBase数据库
的数据定义一个对象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 :(得分:0)
我的问题在于将nsstring
定义为assign
althaugh必须是strong
@property (nonatomic, strong) NSString *miDProperty;