我有一个自定义类对象(catalogItem)的数组(项目)每个catalogItem都有各种属性,其中一个是称为标题的母带
我正在尝试从第二个数组(tempCaption)中的nsstrings更新items数组中每个catalogItem中的这个catalogItem.caption
我知道要遍历数组,但我似乎无法正确使用语法,因为我似乎在做的是每个 catalogItem.caption 循环遍历 tempCaption 数组中的每个 nsstring。所以它迭代了 49 次而不是它应该的 7 次。catalogItem.caption 最终都是 tempCaption 数组中的最后一项。
视图控制器.m
-(void)parseUpdateCaptions
{
NSMutableArray *tempCaptions = [NSMutableArray array];
//get server objects
PFQuery *query = [PFQuery queryWithClassName:@"UserPhoto"];
NSArray* parseArray = [query findObjects];
//fast enum and grab strings and put into tempCaption array
for (PFObject *parseObject in parseArray) {
[tempCaptions addObject:[parseObject objectForKey:@"caption"]];
}
//fast enum through each array and put the capString into the catalogItem.caption slot
//this iterates too much, putting each string into each class object 7 times instead of just putting the nsstring at index 0 in the temCaption array into the catalogItem.caption at index 0, etc. (7 catalogItem objects in total in items array, and 7 nsstrings in tempCaption array)
for (catalogItem in items) {
for (NSString *capString in tempCaptions) {
catalogItem.caption = capString;
DLog(@"catalog: %@",catalogItem.caption);
}
}
}
如果需要 - 类对象 header.h
#import <Foundation/Foundation.h>
@interface BBCatalogClass : NSObject
@property (nonatomic, strong) NSData *image;
@property (nonatomic, strong) NSData *carouselImage;
@property (nonatomic, strong) NSString *objectID;
@property (nonatomic, strong) NSString *caption;
@end