nsmutablearray

How can I determine the index of an object in an NSMutableArray when I search for a NSString within it?

二次信任 提交于 2020-01-05 07:30:15
问题 Currently I am coding the search capability of a UISearchBar using data from a DB that's displayed in a table. I figure out the search results and save them to NSMutableArray *searchResults . Here's how that looks: - (void) searchGrapesTableView { [searchResult removeAllObjects]; numSearchWines=0; for (NSString *str in listOfWines) { NSRange titleResultsRange = [str rangeOfString:searchBar.text options:NSCaseInsensitiveSearch]; if (titleResultsRange.length > 0) { [searchResult addObject:str];

How can I determine the index of an object in an NSMutableArray when I search for a NSString within it?

萝らか妹 提交于 2020-01-05 07:29:05
问题 Currently I am coding the search capability of a UISearchBar using data from a DB that's displayed in a table. I figure out the search results and save them to NSMutableArray *searchResults . Here's how that looks: - (void) searchGrapesTableView { [searchResult removeAllObjects]; numSearchWines=0; for (NSString *str in listOfWines) { NSRange titleResultsRange = [str rangeOfString:searchBar.text options:NSCaseInsensitiveSearch]; if (titleResultsRange.length > 0) { [searchResult addObject:str];

objective c when to use NSDictionary instead of NSArray [duplicate]

▼魔方 西西 提交于 2020-01-04 07:49:26
问题 This question already has answers here : What's the difference between a dictionary and an array? (6 answers) Closed 6 years ago . I'm in a dilemma in terms of which of the two I should use. I will be retrieving a group of data via a restful API (returns json) and I'm not sure how I should store them before I display it on my UI View Table. eg. {"Events":[{"Id":5,"Name":"Event 1 2013"},{"Id":6,"Name":"Event 2 2013"}]} I've been reading tutorials and some would use NSMutableArrays while some

iOS Masonry 等间隔或等宽高排列多个控件

元气小坏坏 提交于 2020-01-03 23:06:42
masonry 目前提供了相应的接口,直接使用即可 1、固定宽高不固定间隔 /* MASAxisType :横排还是坚排 withFixedItemLength : 控件的宽或高 leadSpacing: 第一个控件与边缘的间隔 tailSpacing : 最后一个控件与边缘的间隔 */ mas_distributeViewsAlongAxis:(MASAxisType) withFixedItemLength:(CGFloat) leadSpacing:(CGFloat) tailSpacing:(CGFloat) 2、固定间隔不固定宽高 /* MASAxisType :横排还是竖排 withFixedSpacing: 两个控件间隔 leadSpacing:第一个控件与边缘的间隔 tailSpacing: 最后一个控件与边缘的间隔 */ mas_distributeViewsAlongAxis:(MASAxisType) withFixedSpacing:(CGFloat) leadSpacing:(CGFloat) tailSpacing:(CGFloat) 两个API,分为固定间隔不固定宽高,固定宽高不固定间隔,根据具体需求使用相应的即可。 需要注意的是 : 横排的时候要相应设置控件数组的垂直约束,竖排的时候要相应设置控件数字的水平约束。 例1:水平方向排列、固定控件间隔

best way to load an image library of iphone nsmutablearray (600+ items)

偶尔善良 提交于 2020-01-03 06:27:29
问题 I have created an app which has a library of images. I have imported the images in to my resources folder in Xcode and am currently loading them in to an array in the appDelegate when the app loads. This is happening each time. I am now worried that as the library grows the app will run out of memory. Is there a better way of loading these? the structure is Library > category > image list > image I have an NSMutableArray called mainLibrary which I then add another nsmutablearray for each

Adding items to NSMutableArray and saving/loading

假装没事ソ 提交于 2020-01-02 16:55:52
问题 I've used this tutorial to create an app with a table view that is populated using an NSMutableArray. Now I'd like to add the functionality to add additional items to the array and save/load them. I've customized the Fruit class to look like this: #import <UIKit/UIKit.h> @interface Fruit : NSObject { NSString *name; NSString *instructions; NSString *explination; NSString *imagePath; } @property(nonatomic,copy) NSString *name; @property(nonatomic,copy) NSString *instructions; @property

Does mutableCopy make contained objects mutable?

亡梦爱人 提交于 2020-01-02 10:35:33
问题 myArray is an NSArray of NSDictionary objects. Will [myArray mutableCopy] contain the original NSDictionary objects or NSMutableDictionary copies? Is there a simple way to make an immutable object graph completely mutable? 回答1: If you don't mind the amount of time required for a large object graph and you actually want deep copies of objects, you could serialize your object graph and then deserialize it. The easiest way to do this (assuming all your objects are Foundation Collection Objects)

iPhone: Using a NSMutableArry in the AppDelegate as a Global Variable

北慕城南 提交于 2020-01-01 07:24:09
问题 What i'm trying to accomplish is to have an NSMutableArray defined in the AppDelegate. I then have two UIViewControllers. One view is responsible for displaying the array from the AppDelegate. The other view is used to add items to the array. So the array starts out to be empty. View1 doesn't display anything because the array is empty. The User goes to View2 and adds an item to the array in AppDelegate. Then when the user goes back to View1 it now displays one item. Here is how I'm trying to

iPhone Obj C — Sorting a Mutable Array of dictionaries — display a string but sort by value

六月ゝ 毕业季﹏ 提交于 2020-01-01 06:37:07
问题 I have a NSMutableArray with 30 dictionaries inside of it. Each contains a name and a value. I currently have the names sorted so that the show in a table view alphabetically. However, I'd like to make a UIButton to give the option of STILL DISPLAYING THE NAMES, but ordered by the value. The value doesn't need to be displayed. Also, where in the .m/.h files would these codes be placed? THANKS! 回答1: To be able to help you I need a test data to work with. Let's say your array with data looks

How to convert NSArray to NSMutableArray

痞子三分冷 提交于 2020-01-01 04:00:07
问题 ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook); CFIndex nPeople = ABAddressBookGetPersonCount(addressBook); NSMutableArray *tempPeoples=[[NSMutableArray alloc]init]; for(int i=0;i<nPeople;i++){ ABRecordRef i1=CFArrayGetValueAtIndex(allPeople, i); [tempPeoples addObject:i1]; // [peoples addObject:i1]; }// end of the for loop peoples=[tempPeoples copy]; This code gives exception b/c I want to convert NSMutableArray to