你好,並感謝所有, 這裏是的情況,當我使用下面的方法填充我的數組時,它適用於當我使用Methode 2時它不起作用。目的是改變文字的顏色。兩種方法都是NSLOGED,數據是相同的。數組如何在ios中填充之間的區別?
第一種方式。(工作名稱被變灰)
-cellForRowAtIndexPath
....
if ([self.secArray containsObject:indexPath]) {
cell.textLabel.textColor = [UIColor grayColor];
} .....
-didSelectRowAtIndexPath:
...
[secArray addObject:indexPath];
第二種方式(不工作 - 填充從我的.plist陣列)
-cellForRowAtIndexPath
....
if ([self.secArray containsObject:indexPath]) {
cell.textLabel.textColor = [UIColor grayColor];
} .....
-viewWillAppear
NSString *filePathOrdersIndex = [self dataFilePathOrders];
NSMutableArray *chekDist;
chekDist = [[NSMutableArray alloc] initWithContentsOfFile:filePathOrdersIndex];
NSLog(@"data checkDist........... %@", chekDist);
if(!chekDist){
chekDist = [[NSMutableArray alloc]init];
}
for(id dist_data in chekDist){
secArray = [dist_data objectForKey:@"myIndexPath"];
//[secArray addObject:[dist_data objectForKey:@"myIndexPath"]];
}
兩種方法登錄到控制檯兩個數組包含相同的陣列數據....但第二種方式不起作用
任何幫助,非常感謝。
這可能是因爲是的Plist NSDictionary的陳述...... – CodaFi
@CodaFi,你能詳細闡述表示???? – AhabLives
@CodaFi是的,如果'NSIndexPath'的'description'方法的實現打印類似於字典的文本,那麼NSLog消息甚至可能顯示相同。 @AhabLives:他的意思是在第二種方法中,因爲你是從plist加載的,你可能會看到存儲在「myIndexPath」鍵中的「NSDictionary」實例,而不是實際的「NSIndexPath」實例。 –