nsarray

UITable is not getting populated with NSMutableArray

六眼飞鱼酱① 提交于 2019-12-07 00:24:28
In my app i have a text field where if i enter a word i should get all the file names starting with the particular word into a UITable. Here i am getting these file names into an array and its available in NSLog too... But the table remains empty always. Control is not entering into table(NSLog in tables method is not getting displayed). Can anyone help me? my code is -(IBAction)Do_Search:(id)sender { files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: [[NSBundle mainBundle] bundlePath] error:nil]; search_results_array = [files filteredArrayUsingPredicate: [NSPredicate

Difference between @[] and [NSArray arrayWithObjects:] [duplicate]

落花浮王杯 提交于 2019-12-06 23:52:04
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Should I prefer to use literal syntax or constructors for creating dictionaries and arrays? Is there any difference between: NSArray *array = @[@"foo", @"bar"]; and NSArray *array = [NSArray arrayWithObjects:@"foo", @"bar", nil]; Is one of those more stable, faster, or anything else? 回答1: This documentation doesn't mention anything about efficiency directly, but does mention that NSArray *array = @[@"foo", @"bar

NSString stringWithContentsOfURL is deprecated. What should I do?

拈花ヽ惹草 提交于 2019-12-06 23:45:50
问题 I've written some code that uses stringWithContentsOfURL , but it turns out that it is now deprecated. Can you help me replace it? Here's my code: NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]]; NSArray *listItems = [locationString componentsSeparatedByString:@","]; Additionally, can someone have some sample code to show how it works? What encoding was the original code done in (in my 2 lines above)? I want to maintain compatibility so what

Getting UITableView to populate with data from another class

雨燕双飞 提交于 2019-12-06 17:12:05
问题 I am quite new to Objective-C and this is the first time I have attempted to implement MVC. I have a model class where l have an NSArray which will be populated with data from a JSON object. I want to populate my UITableView (in my view controller class), with objects from this array. Please review my code: Droplets.h @interface Droplets : NSObject { NSArray *dropletsArray; } // Get droplets data - (void) getDropletsList; //Object initilization - (id) init; //Public properties @property

Objective-C how to pull several random items out of NSArray without getting duplicates? [duplicate]

爷,独闯天下 提交于 2019-12-06 16:56:41
This question already has answers here : Getting a random object from NSArray without duplication (3 answers) Closed 3 years ago . I have an array of random properties I would like to assign to equipment within the game I'm developing. The code that I use below is returning an NSArray. I'm interested if there's way to get item indices from that array without getting duplicate values. The obvious solution is to create a mutable array with the returned array, do random, remove item that was returned and loop until the number of items is received. But is there a different way of getting X random

Create NSIndexSet from integer array in Swift

独自空忆成欢 提交于 2019-12-06 16:29:34
问题 I converted an NSIndexSet to an [Int] array using the answer at https://stackoverflow.com/a/28964059/6481734 I need to do essentially the opposite, turning the same kind of array back into an NSIndexSet. 回答1: Swift 3 IndexSet can be created directly from an array literal using init(arrayLiteral:), like so: let indices: IndexSet = [1, 2, 3] Original answer (Swift 2.2) Similar to pbasdf's answer, but uses forEach(_:) let array = [1,2,3,4,5,7,8,10] let indexSet = NSMutableIndexSet() array

Parse XML item “Category” into an NSArray with NSDictionary

爱⌒轻易说出口 提交于 2019-12-06 16:21:57
问题 Question: The generated XML file from an .XSD template produces the output pasted below. Since category 's keys are image , my standard way of parsing the image items wont work on category . I would like to place the category name="Category #" into an array, How can I make an array from the category fields. What I need: What I want is an array of dictionaries. Each position contains a dictionary representing one category, and each dictionary contains images for that category. Array: @

Pick closest NSNumber from array

纵然是瞬间 提交于 2019-12-06 16:02:57
问题 I have an array with a bunch of NSNumber s. From an UISlider I get a certain value when the user stops dragging it. I would like to get the closes number from the array. So for instance, if the user drags the UISlider to 13 , and the NSArray contains the NSNumbers with 10 and 15 ; I want to get 15 from the array. Example of array: NSArray *values = [NSArray arrayWithObjects:[NSNumber numberWithInt:15], [NSNumber numberWithInt:20], [NSNumber numberWithInt:30], [NSNumber numberWithInt:45],

tableView:didSelectRowAtIndexPath: call to current-view Parser delegates

守給你的承諾、 提交于 2019-12-06 15:53:36
I have some pretty interesting logic going, basically I have this data which I want to check over before I display the next view.. just in case the data is empty I want to pop the view, if the data is not empty then I want to load the the view to display it onto the navigational stack. so in my tableView:didSelectRowAtIndexPath: method, when the selection is made I, get the current selection ID number so I can restrict the values of the data Im going to parse to only related values. This is what the code looks like inside my method. #pragma mark - Table view delegate - (void)tableView:

select indexOfObject from NSArray in Xcode by comparing string

邮差的信 提交于 2019-12-06 15:00:18
问题 Hi I have NSarray values in Xcode. I need to get array indexOfObject by comparing string values. my array values are ( { firstName = lord; lastname = krishna; }, { firstName = priya; lastname = amirtha; } ) If I type first name in textfield and click button means last name want to display in another textfield. thank you. 回答1: To answer the title of your question: NSString *compareString = @"something"; NSMutableArray *indexesOfMatches = [[NSMutableArray alloc]init]; for (NSString *string in