Tag: nsarray

insertItemsAtIndexPaths更新错误

在UICollectionView中,我正在尝试使用performBatchUpdates:completion来更新我的网格视图。 我的数据源数组是self.results 。 这是我的代码: dispatch_sync(dispatch_get_main_queue(), ^{ [self.collectionView performBatchUpdates:^{ int resultsSize = [self.results count]; [self.results addObjectsFromArray:newData]; NSMutableArray *arrayWithIndexPaths = [NSMutableArray array]; if (resultsSize == 0) { [arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:0 inSection:0]]; } else { for (int i = 0; i < resultsSize; i++) { [arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:resultsSize + i inSection:0]]; } } for (id obj in self.results) […]

我如何轻松从NSString中删除逗号?

我有一个UILabel与以下文本: Medium, Black 我打算做的是抓住string中的单词,并插入每个可变数组,以便我可以稍后使用每个标题来确定一些东西。 以下是我如何做到这一点: NSMutableArray *chosenOptions = [[[[cell tapToEditLabel] text] componentsSeparatedByString: @" "] mutableCopy]; NSString *size = [chosenOptions objectAtIndex:0]; NSString *colour = [chosenOptions objectAtIndex:1]; 我logging了这两个NSString,大小返回“中”,颜色正确返回“黑色”。 由于逗号,我的比较结果总是错误的: itemExists = [[item colour] isEqualToString:colour] && [[item size] isEqualToString:size] ? YES : NO; 这个逗号导致itemExists总是等于NO。 请欣赏代码中的简单解决scheme。 解决scheme只需要删除逗号而不是其他字符。 当处理女性的服装尺寸时,我使用如下string的尺寸:“[8 UK]”,所以删除非字母数字字符将删除这些字符。 所以我真的需要一个解决scheme来处理逗号。 谢谢你的时间。

NSDictionary添加NULL keyvalue

所以我创build了一个NSDictionary,它提供了一个要使用的方法数据,但是keys数组中的一些键值不会总是被值填充。假设我有18个键(我这样做)..我可能只有在一次通话中使用5,而在另一个通话中使用5,或者在我的代码中的某些时候使用18。 我想知道的是我怎样才能将NULL值添加到这些键,所以稍后当我通过keyvalue对看,我可以看到哪些键我需要担心,哪些我可以忘记? 所以问题是,如果我想不添加任何/ null的一个关键如何做到这一点,而不会造成错误,或认为它的数组结尾nil .. 这是我目前的,但只要我尝试阅读NSDicionary它给我一个不好的EXE错误 NSDictionary * sendSeriesDictionary = [[NSDictionary alloc] init]; NSArray *keys = [NSArray arrayWithObjects:@"Code", @"MaID", @"MoID", @"SuID",@"SMID",@"Ye",@"KID",@"KBlID",@"KBk",@"CaID",@"Caer",@"Loe",@"Kepe",@"KTGroup",@"Cesc",@"LID",@"IN",@"LaID", nil]; NSArray *objects = [NSArray arrayWithObjects: NULL, manufactureIdString, modelIdString, subModelIdString, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, nil]; sendSeriesDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys]; 只是为了让你知道键名将被改变,这只是为了testing/例如如何做到这一点。 任何帮助将不胜感激。

从两个数组中获取唯一的数字

如果我有几个NSArrays填入整数或NSNumbers ,如下所示: A: { 12, 23, 45, 56, 67, 78, 99, 234 } B: { 12, 56, 78, 99, 454, 512 } 如何输出数字在A中,但不在B中的数组 { 23, 45, 67, 234 }

用NSPredicate过滤NSArray

我想过滤一个User对象的数组( User有fullname , user_id和一些更多的属性..)根据firstName或lastName开始一些string。 我知道如何根据一个条件过滤: NSPredicate* predicate = [NSPredicate predicateWithFormat:@"firstName BEGINSWITH[cd] %@", word]; NSArray* resArr = [myArray filteredArrayUsingPredicate:predicate]; 这将给我所有的用户,有一个firstName以“单词”开头。 但是如果我想让所有具有以“word”开头的firstName或lastName的用户呢?

将NSArray与NSDate对象按月分类到NSDictionary中

我正在构build一个UITableView并希望按月分组,以便我可以将这些string作为我的部分标题,例如: February 2013 – Item 1 – Item 2 January 2013 – Item 1 – Item 2 我有一个NSArray具有一个NSDate pubDate属性的自定义对象。 我如何使用NSDate对象按月将我的自定义对象分组到一个NSDictionary ?

从parse.com获取objectId

所以我正在构build一个使用parsing作为后端的应用程序。 我已经写了我自己的,但我想我会节省一些时间,并使用parsing。 我用parsing的数据填充表视图,这很好。 我想抓取从parsing数组构build的字典中的objectId。 我的数组的输出如下所示: <news_events:pdbIEvOteH:(null)> {\n eventDescription = \"This is a test description.\";\n eventMessage = \"This is a test message.\";\n eventTitle = \"Free Wi-Fi Now Available!\";\n} 在上面的例子中,对象ID是pdbIEvOteH 。 我起初试图通过使用获取id: NSString * objectId = [myDictionary objectForKey:@"objectId"]; 但是,返回null。 我知道这是不是我的字典问题,因为我可以得到其他信息。 问题是它看起来像上面的数组中没有关键的objectId 。 正如你可以看到它遵循news_events 。 我知道你可以用PFObject得到它,但我不确定是否可以用PFObject填充表。 所以底线是如何获得objectId 。

将对象添加到另一个View Controller中的数组

我有一个HomeViewController有一个tableView填充数组tableViewArray (最初为空)。 当我点击一个barButton时,我模式地延续到另一个名为OutsideViewController View Controller,它具有由另一个数组填充的另一个tableView。 我想要做的是以下几点: 当我在我的OutsideViewController点击一行时,我想将所选的string值添加到tableViewArray以便当我回到HomeViewController ,tableView具有在tableView中列出的新项目。 到目前为止,这是我曾经试过的: 在我的OutsideViewController.m的-didSelectRowAtIndexPath方法中,我有这段代码: NSString *selectedRow = [outsideArray objectAtIndex:indexPath.row]; NSMutableArray *temporaryArray = [NSMutableArray arrayWithObject:selectedRow]; HomeViewController *homeVC = [[HomeViewController alloc] init]; homeVC.tableViewArray = temporaryArray; 该代码的作品,但HomeViewController的tableView仍然是空的,当我返回。 我必须重新加载tableView数据吗? 我做对了吗? 这是我如何在故事板中设置我的视图控制器: HomeViewController -(modal segue)-> Navigation Controller –> OutsideViewController 此外,从OutsideViewController返回到HomeViewController是由这行代码完成的: [self dismissViewControllerAnimated:YES completion:^{ }];

NSArray的NSArray中的对象的属性的NSPredicate

我有一个像下面的结构的对象:事务有一个项目的数组。 Item有一个SubItems数组 @interface Transaction : NSObject @property (nonatomic, copy) NSString *id; @property (nonatomic, assign) NSInteger status; @property (nonatomic, strong) NSArray *items; // array of Item @end @interface Item : NSObject @property (nonatomic, copy) NSString *identifier; @property (nonatomic, assign) NSInteger price; @property (nonatomic, strong) NSArray *subitems; @end @interface SubItem : NSObject @property (nonatomic, copy) NSString *name; […]

尽pipe有mysql入口,NSArray在iOS中仍然是空的

我一直在尝试用xml输出从PHP脚本中填充Xcode中的数组,以便ios可以连接到mysql。 但是,尽pipe在mysql中有信息,我仍然得到了一个空数组。 这一定意味着我的属性部分或者我对xml的parsing是错误的,但是我真的不知道它究竟是什么错误(并且没有任何数量的主演似乎有帮助)。 我没有得到任何错误从PHP或Xcode。 有任何想法吗? 编辑:我已经按照下面的build议,我仍然得到一个空值,但我相信它来自我的PHP … – (void)viewDidLoad { [super viewDidLoad]; char *cStr = "YES"; NSString *str3 = [NSString stringWithUTF8String:cStr]; NSString *urlString = [NSString stringWithFormat:@"(censored)", _login]; NSXMLParser *Parser = [[[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:urlString]] autorelease]; [Parser setDelegate:self]; [Parser parse]; NSDictionary *itemAtIndex =(NSDictionary *)[oneam objectAtIndex:0]; oneam = [[NSMutableArray alloc] init]; if (([[itemAtIndex objectForKey:@"its"]isEqualToString:str3 ])) { [switch1 […]