自定義類對象的自定義類對象的數組我有一個數組(項目)(catalogItem)每個catalogItem具有各種性質其中之一是一個母帶稱爲字幕更新從第二陣列
我試圖更新第二個數組中的nsstrings的items數組中的每個catalogItem中的catalogItem.caption(tempCaption)
我知道遍歷數組,但我似乎無法獲得正確的語法,因爲我似乎在做的是每個catalogItem.caption遍歷tempCaption數組中的每個nsstring。所以它重複49次而不是7次。 catalogItem.caption最終都是tempCaption數組中的最後一項。
ViewController.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
此方法工作除了我不得不改變[數組objectatindex:我] .caption catalogItem = [items objectAtIndex:i]; catalogItem.caption = [tempCaptions objectAtIndex:i]; – BigB
酷,預計。我已經更新了答案,所以任何人都會看到它。出於好奇, –