Tag: nsmutablearray

将数组从一个视图添加到另一个视图并保留值

我有四个视图,有四个数组。 只要我从一个视图导航,我将这个特定的数组添加到我的主数组。 最初这个主数组没有任何内容,并且在应用程序使用“init”方法运行时被分配。 它没有视图,它是NSObject一个子类的数组。 最后主数组应该由{viewarray1,viewarray2,viewarray3,viewarray4}组成。 在导航到下一个视图时,每个数组都添加到主数组中。 那么我的执行有什么问题吗? 可以在init方法中分配masterArray吗? 每次我添加一个对象到masterArray ,我NSLog它,它显示(null) 如何让主数组保留整个应用程序的值? 关于守则的一些信息 : 我在另一个类中初始化我的主数组,在-(init)方法中 masterArray = [[NSMutableArray alloc] init ]; 在从另一个视图向MasterArray添加对象的同时,我引用该类,并为该类创build一个对象,并将其添加为property并将其synthesize 。 我然后使用 [self.thatClassObject.masterArray addObject:self.viewArray1];

迭代时是否可以从mutablearray中删除字典?

for (int i = 0; i< [optionDataArr count]; i++) { NSString *sName = [[optionDataArr objectAtIndex:i] objectForKey:kOptionName]; NSString *sPrice = [[optionDataArr objectAtIndex:i] objectForKey:kOptionExtraPrice]; if (sName.length == 0 && sPrice.length == 0) { [optionDataArr removeObjectAtIndex:i]; } } 假设optionDataArr包含一个没有值的字典,当上面的代码执行时,我收到: Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

TableViewCells和字典数组

我无法理解如何用所有的date填充我的表。 只返回2012年9月1日至2012年8月31日。 我已经尝试了一些东西,如使用我的天和插槽numberofrowsctions。 我认为这与.count有关,但是没有看到。 但是我还没有弄明白。 它仍然只是发布9/1字典。 如何在tableviewcell中显示所有字典的数组,我希望我的意思是,附图。 我的代码: NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error]; NSDictionary* myslots =[json objectForKey:@"slots"]; NSLog(@"allslots: %@", myslots); for (NSString *slotKey in myslots.allKeys) { NSDictionary *slot = [myslots valueForKey:slotKey]; UPDATED: self.timesArray = [[NSMutableOrderedSet alloc] init]; for (NSDictionary *myDays in slot){ if ([[myDays objectForKey:@"isReservable"] isEqualToNumber:[NSNumber numberWithInt:1]]) [self.timesArray addObject:[myDays objectForKey:@"begin"]]; //NSLog(@"This is the […]

被NSMutableArraysorting使用描述符:exception

以下方法: – (NSMutableArray*) timeSortedBegins { NSMutableArray* begins = [self.spans valueForKey: @"begin"]; NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey: @"cycleOffsetObject" ascending: YES]; [begins sortUsingDescriptors: @[sort]]; return begins; } 抛出这个运行时exception: 2014-03-21 14:41:32.482 myValve[1741:60b] -[__NSArrayI sortUsingDescriptors:]: unrecognized selector sent to instance 0x16d7bc20 2014-03-21 14:41:32.484 myValve[1741:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI sortUsingDescriptors:]: unrecognized selector sent […]

保存NSArray到iCloud并检索它

我有一个应用程序,目前将一个NSMutableArray保存到iPad上的文档目录中的文件。 这是保存的 [residentData writeToFile:filePath atomically:NO]; 并被读回; residentData = [[NSMutableArray alloc] initWithContentsOfFile:filePath]; 我需要将这个文件写入iCloud,因为数据需要在多个设备上可用。 我已经尝试以下在iCloud中创build文件; NSData *myFileData = [NSKeyedArchiver archivedDataWithRootObject:residentData]; [fileManager createFileAtPath:[icloudURL path] contents:myFileData attributes:nil]; 这确实在正确的地方创build了一个文件。 我努力了解如何将这个文件读回我的NSMutableArray(residentData)。 我努力了; residentData = [NSKeyedUnarchiver unarchiveObjectWithData:myFileData]; 但是这不能正确解码到数组中。 请有人告诉我我的方式的错误 – 我怀疑我的一个根本的误解是NSData的责任,但任何指针将受到欢迎。

需要遍历存储在Parse.com数据库中的数组内的NSMutableArray

我有一个包含NSString对象的NSMutableArray对象。 可变数组对象被称为_usersToAddToFriendsList 。 当我完成添加NSString对象时,我为Parse.com运行以下代码: [PFUser currentUser]; PFQuery *query = [PFQuery queryWithClassName:@"_User"]; [query whereKey:@"username" equalTo:_userSubmittedUsername]; [query getObjectInBackgroundWithId:_objectId block:^(PFObject *object, NSError *error) { object[@"friends"] = _usersToAddToFriendsList; [object saveInBackground]; }]; 最重要的部分是这个声明: object[@"friends"] = _usersToAddToFriendsList; 这需要我的NSMutablearrays,并把它放在我的Parse.com数据库的“朋友”列。 当我在Parse中创build这个列时,我把它设置为“type”到“array”。 所有这些工作都很完美,我可以看到我的可变数组的内容已经放在数据库的“朋友”列中。 这是问题,但。 后来,当我查询“朋友”列时,我使用findObjectsInBackgroundWithBlock的方法调用,并将服务器返回的对象放入名为“objects”的NSArray对象中。 我的问题是,这意味着我现在有一个名为“对象”的数组包含我的原始可变数组与我的NSString。 我需要遍历我的原始NSMutableArray的string值,但我不知道如何去他们,因为我原来的可变数组包含在服务器返回的这个新的NSArray内。 我曾尝试过各种multidimensional array解决scheme,人们在我之前的堆栈溢出问题中提供: 需要遍历另一个数组内部的数组 但它永远不会工作,它总是在xcode崩溃,并说: -[PFUser countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 这让我觉得这个问题需要专门针对Parse.com如何工作的解决scheme。 我只是想能够访问和循环我最初存储在我的NSMutableArray中的string值。

在nsmutablearray单独的未来date

我有一个可变数组,我只有过去的date,当前date和将来的date。 我必须将未来的date和存储分隔到另一个数组中。 你可以帮我吗。 这是我的数组: uniqueItems( "2015-03-01", "2015-02-28", "2015-02-22", "2015-02-21", "2015-02-20", "2015-02-15", "2015-02-14", "2015-02-13", "2015-02-08", "2015-02-07", "2015-02-01", "2015-01-31", "2015-01-30", "2015-01-25", "2015-01-24", "2015-01-18", "2015-01-17", "2015-01-16", "2015-01-11", "2015-01-10", "2014-12-07" 我试过这个编码,但是没有工作。 NSDate *currentDate = [NSDate date]; NSDate* dateAdded=(NSDate*)[uniqueItems objectAtIndex:0]; double min = [currentDate timeIntervalSinceDate:dateAdded]; int minIndex = 0; for (int i = 1; i < [uniqueItems count]; ++i) { […]

NSMutableArray索引混合起来

我目前正在尝试iCarousel Multiple Carousel例子。 在我的数组中,我用NSMutableDictionary添加图像: 我有两个这样的:(myImages和myImages2我的两个插槽加载在ViewDidLoad旋转木马) self.myImages = [NSMutableArray array]; for(int i = 0; i <= 10; i++) { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [paths objectAtIndex:0]; NSString *savedPath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"myImages%d.png", i]]; if([[NSFileManager defaultManager] fileExistsAtPath:savedPath]){ NSMutableDictionary *container = [[NSMutableDictionary alloc] init]; [container setObject:[UIImage imageWithContentsOfFile:savedPath] forKey:@"image"]; [container setObject:[NSNumber numberWithInt:i] forKey:@"index"]; [images addObject:container]; […]

有序arrays与Firebase

由于Firebase不能保证在从基础读取时的顺序,我们可以从这个asynchronous调用获得无序的输出: -(void)loadDataFromFirebase { handles = [[NSMutableArray alloc] init]; Firebase* listRef = [[Firebase alloc] initWithUrl:@"https://mobilefeast.firebaseIO.com/foodtrucks"]; [listRef observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) { NSLog(@"%@", snapshot.name); [handles addObject:snapshot.value]; [self.handleTableView reloadData]; }]; } 在从Firebase中读取片段的例子中,我们可以命令打印asynchronous数据,但是对于iOS中的NSArrays来说,这并不适用,其中不存在hole-y稀疏数组。 从iOS的Firebase中按顺序填充数组的正确方法是什么? 我认为这可以通过添加一个.json文件来完成,这个.json文件添加到一个REST调用的URL的末尾,但是想试图使用原生的Firebase iOS API。 谢谢。 * 编辑:*寻找一个简单的字母sorting。 看起来这应该发生在Rest中,并在REST中使用以下URL: https://mobilefeast.firebaseio.com/foodtrucks/.json 但我似乎无法复制与iOS Firebase API相同的顺序。

与NSMutableArray比较

在我的Array 1 ,我从NSDocumentDirectory加载图像,我加载他们,并添加一个NSMutableDictionary : self.images = [NSMutableArray array]; for(int i = 0; i <= 8; i++) { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [paths objectAtIndex:0]; NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Images%d.png", i]]; if([[NSFileManager defaultManager] fileExistsAtPath:savedImagePath]){ NSMutableDictionary *container = [[NSMutableDictionary alloc] init]; [container setObject:[UIImage imageWithContentsOfFile:savedImagePath] forKey:@"image"]; [container setObject:[NSNumber numberWithInt:i] forKey:@"index"]; [images addObject:container]; } […]