nsarray

Reloading UITableView shows error?

一个人想着一个人 提交于 2019-11-29 13:04:59
I am in a strange situation . when i try to reload the tableview using reloadData() it shows the following error . . . fatal error: unexpectedly found nil while unwrapping an Optional value Here is the web service method that retrieves output func didRecieveOutput(results:NSArray) { if results.count != 0 { userOrders = results as! NSMutableArray dispatch_async(dispatch_get_main_queue(), { () -> Void in self.orderList.reloadData() }) } } Edit : I had checked my connection as well as delegate & datasource . It works fine with static data . But problem came when I called reloadData(). I had the

NSDictionary value replacing instead of adding in Plist

孤人 提交于 2019-11-29 12:12:05
hi i tried to add values(book id,page number,notes) from NSdictionary to Plist but each time the new value replacing the previous one?but i need all values in plist my code for adding dictionary to plist is NSString *bid=@"95"; NSString *pnum=@"12"; userNotes=[[NSMutableDictionary alloc]init]; [userNotes setValue:userNotesTextview.text forKey:@"notes"]; [userNotes setValue:bid forKey:@"bookid"]; [userNotes setValue:pnum forKey:@"pagenumber"]; userNotesView.hidden=YES; _background.hidden = YES; userNotesTextview.text=@""; [self savingMetaData]; NSMutableArray *notes=[[NSMutableArray alloc]init]

Loading images for animation in UIImageView - iOS

拟墨画扇 提交于 2019-11-29 11:10:06
I have around 300 images to be loaded for animation the images are named loading001.png, loading002.png, loading003.png, loading004.png………loading300.png I am doing it in the following way. .h file #import <UIKit/UIKit.h> @interface CenterViewController : UIViewController { UIImageView *imgView; } @end .m file @implementation CenterViewController - (void)viewDidLoad { [super viewDidLoad]; imgView = [[UIImageView alloc] init]; imgView.animationImages = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"loading001.png"], [UIImage imageNamed:@"loading002.png"], [UIImage imageNamed:@

Grouping NSArray of NSDictionary based on a key in NSDictionay

坚强是说给别人听的谎言 提交于 2019-11-29 10:39:51
I am trying to filter out a NSArray of NSDictionaries. With my below example, I want dict1, dict2 & dict4 grouped in one array, dict3 & dict5 grouped in second array and dict6 in third array. I am getting this data in NSArray, so essentially the "orig" array below is my input and I know that I need to do grouping based on "Name" key. Instead of looping through the NSArray I though of using valueForKeyPath to return me array based on the key path but this does not work (crashes with logs -[NSMutableArray addObjectsFromArray:]: array argument is not an NSArray'). Any suggestion. NSDictionary

Evaluating an NSPredicate on a NSArray (without filtering)

这一生的挚爱 提交于 2019-11-29 09:23:31
问题 Is it possible to evaluate a NSPredicate on a NSArray, without having the NSPredicate starting to filter out objects in the array? For instance, say I have the following predicate that just checks the number of objects in an array: NSPredicate *pred = [NSPredicate predicateWithFormat:@"count == 3"]; NSArray *list = [NSArray arrayWithObjects:@"uno", @"dos", @"volver", nil]; BOOL match = [pred evaluateWithObject:list]; This will crash, as pred will try to retrieve the "count" key from the first

NSPredicate on array of arrays

大城市里の小女人 提交于 2019-11-29 07:59:13
I have an array, that when printed out looks like this: ( ( databaseVersion, 13 ), ( lockedSetId, 100 ) ) Would it be possible to filter this using an NSPredicate (potentially by the index in the array). So something like: give me all rows where element 0 is 'databaseVersion'? I know that if I had an array of dictionaries I could do this with a predicate similar the one found here , but I found that when using dictionaries and storing a large amount of data, my memory consumption went up (from ~80mb to ~120mb), so if possible I would to keep the array. Any suggestions on how this might be done

How to sort a NSArray which contains NSDictionary?

自作多情 提交于 2019-11-29 07:39:18
I have a plist like this: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>highscores</key> <array> <dict> <key>highscoreInSeconds</key> <string>9</string> <key>levelName</key> <string>1</string> <key>name</key> <string>Black</string> </dict> <dict> <key>highscoreInSeconds</key> <string>12</string> <key>levelName</key> <string>1</string> <key>name</key> <string>Black</string> </dict> </array> </dict> </plist> Now I want to sort this by the highscoreInSeconds . NSArray

how to sort an NSArray using compare:options

纵然是瞬间 提交于 2019-11-29 07:17:14
I have an NSArray containing numbers as NSString objects. ie. [array addObject:[NSString stringWithFormat:@"%d", 100]]; How do I sort the array numerically? Can I use compare:options and specify NSNumericSearch as NSStringCompareOptions ? Please give me an example/sample code. You can use the example code given for the sortedArrayUsingFunction:context: method which should work fine for NSStrings too as they also have the intValue method. // Place this functions somewhere above @implementation static NSInteger intSort(id num1, id num2, void *context) { int v1 = [num1 intValue]; int v2 = [num2

How might I check if a particular NSString is present in an NSArray?

风流意气都作罢 提交于 2019-11-29 05:33:11
How might I check if a particular NSString is presnet in an NSArray? You can do it like, NSArray* yourArray = [NSArray arrayWithObjects: @"Str1", @"Str2", @"Str3", nil]; if ( [yourArray containsObject: yourStringToFind] ) { // do found } else { // do not found } Iterating or containsObject are order n ways to find. If you want constant time lookup, you can also maintain a hash table like NSSet or NSHashTable but that increases space but saves time. NSArray* strings = [NSArray arrayWithObjects: @"one", @"two", @"three", nil]; NSSet *set = [NSSet setWithArray:strings]; NSString* stringToFind = @

Use NSArray to specify otherButtonTitles?

邮差的信 提交于 2019-11-29 04:29:23
问题 UIAlertSheet's constructor takes an otherButtonTitles parameter as a varg list. I'd like to specify the other button titles from an NSArray instead. Is this possible? i.e. I have to do this: id alert = [[UIActionSheet alloc] initWithTitle: titleString delegate: self cancelButtonTitle: cancelString destructiveButtonTitle: nil otherButtonTitles: button1Title, button2Title, nil]; But since I'm generating the list of available buttons at runtime, I really want something like this: id alert = [