nsmutablearray

Searching through an array of dictionaries

廉价感情. 提交于 2019-12-12 08:59:56
问题 I'm making an iPhone app which displays information about red wines. The wines are stored in a plist containing an array of dictionaries. I'm adding a search view controller to the application, and to start up easy I want to get the wines who the value for the "Name" key contains nameString (from textbox). It kind of stops here, I need some advices about the most suitable way of doing this. Is there a function in the NSArray class which will do the job, should bring in NSPredicate,

Copy object at specific index of mutable array to the end of another array

橙三吉。 提交于 2019-12-12 05:59:54
问题 I have a mutable array that has a range of numbers (that are changed dynamically later on if that helps), I grab a random number's index from that array and want to stick it in another array (also mutable). I'm not sure how to grab the object at a certain index and copy it. Here's what I tried to do: [btnRange addObject:@"12"]; [btnRange addObject:@"13"]; [btnRange addObject:@"14"]; [btnRange addObject:@"17"]; [btnRange addObject:@"18"]; [btnRange addObject:@"19"]; //start randomising and

objective C: use NSMutableArray in different classes

佐手、 提交于 2019-12-12 05:39:43
问题 I created two UIImageView *image1 and *image2, after I created a NSMutableArray *arrayImage, now I want fill this array arrayImage = [[NSMutableArray alloc] initWithObjects: image1, image2, nil]; but I created UIImageView and NSMutableArray in a ClassA but I want fill the NSMutableArray in the viewdidload in .m of ClassB, then Xcode tell me that image1 and image2 are undeclared. I just used property and synthesize. What can I do? 回答1: You can try something like this, you have to keep a

How should I fix this code?

百般思念 提交于 2019-12-12 05:36:59
问题 I'm trying to sort an array of people objects. The class looks like this. Person ------- name phone I have an NSMutableArray filled with these objects. I want to sort this array by the name of each person object. This is the code I tried. NSSortDescriptor *desc = [[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES]; [personArray sortedArrayUsingDescriptors: [NSMutableArray arrayWithObject: desc]]; It doesn't work. How can it be changed to work? 回答1: You're aware that

how to compare 2 NSMutableArray and get different number of value

只愿长相守 提交于 2019-12-12 05:29:41
问题 I want compare 2 NSMutableArray values and check which indexPath is different and store this numbers of index in one array. for example I have these NSMutableArray : NSMutableArray *a = [[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6", nil]; NSMutableArray *b = [[NSMutableArray alloc]initWithObjects:@"11",@"2",@"5",@"3",@"53",@"6", nil]; and I want to compare these two NSMutableArray index to index (compare value to value) and tell me that which index of array in these

NSMutableArray always empty?

天涯浪子 提交于 2019-12-12 05:29:18
问题 Still have some difficulties to understand Obj-C's gestion of memory and some of its concepts. So my main class contains a NSMutableArray containing some characters and their list of weapons. It's like this : In Main class.h @property (nonatomic, retain) NSMutableArray *players; In Main class.m's init for(int i = 0 ; i < 30 ; i++) { [players addObject:[[PlayerInGame alloc] init:[self.tabPlayers objectAtIndex:i] :[self.tabWeapons:objectAtIndex:i]]]; } PlayerInGame.h @property (nonatomic,

UILabel in UITableViewCell to make a customised cell without making separate class

若如初见. 提交于 2019-12-12 05:03:12
问题 In my table view cell i need to display the contents of my array elements in a single cell and if i insert any new contents the previous contents are not to be overwritten.The previous content and my new content should be displayed in order.Here is my code - (void)viewDidLoad { [super viewDidLoad]; NSMutableArray *arrMain=[NSMutableArray arrayWithObjects: cnfqty, cnftitle, cnfrate, nil]; finarray=[[NSMutableArray alloc]init]; [finarray addObjectsFromArray:arrMain]; NSLog(@"%@",finarray); } -

Can the selected images from library be stored in an array?

半世苍凉 提交于 2019-12-12 04:56:23
问题 I have built a sample project on camera and library. Now, my question is can I store the images that I am selecting from library into an array? I am using this code. UIImage *chosenImage = info[UIImagePickerControllerEditedImage]; [self.arrImages addObject:chosenImage]; Now by placing breakpoints, I came to know that, in my array always 1object is storing even after I chosen images for more than one times. Can anyone give my any idea how can I do it? Any help is highly appreciated. 回答1: Try

Parsing JSON string to a NSMutableArray

為{幸葍}努か 提交于 2019-12-12 04:53:38
问题 This is my string: [{"id":"1","nome":"Adriatik"},{"id":"2","nome":"Ard"},{"id":"3","nome":"Albana"},{"id":"4","nome":"Adriana"}] I would like to parse all 'name' of the JSON string into a NSMutableArray . Sorry for my english! 回答1: Whenever I have to handle some JSON code, the first thing I like to do is create a class based on the JSON text. So, for example if your JSON is representing a U.S. state, create a "State" class. There's a cool little product that you can use for this. It's called

i cannot remove duplicate objects in a NSArray iphone

爱⌒轻易说出口 提交于 2019-12-12 04:32:21
问题 I'm going crazy right now. I have a NSMutableArray with a bunch of Person objects. I want to remove the duplicated objects but it won't work. This is what i got: NSMutableArray *withoutDoubles =[[NSMutableArray alloc]init]; NSArray *temp = [[NSArray alloc] initWithArray:tempResults]; for (Person *person in temp) { if(![withoutDoubles containsObject:person]) { [withoutDoubles addObject:person]; } } for (Person *person in withoutDoubles) { NSLog(@"----> %@",person.name); } That is not working,