Tag: nsmutablearray

在一个未知的NSMutableArray深度中search一个值

好吧,我问了一个错误的问题,所以我编辑了原来的问题。 我在数组中存储数组,以及NSDictionaries。 它是一种实用的应用程序,没有设置结构,用户可以根据需要input嵌套信息。 理想情况下,我需要一个方法来滚动我的数组的所有内容给定一个参数(一种类,也许是一个字典键)。 这是一个例子.. NSMutableArray *array = [[NSMutableArray alloc]init]; NSMutableDictionary *enteredItem = [[NSMutableDictionary alloc]init]; [enteredItem setObject:@"i'm a title" forKey:@"title"]; [enteredItem setObject:@"i'm an id" forKey:@"id"]; [enteredItem setObject:@"i'm a description" forKey:@"description"]; [enteredItem setObject:@"i'm a timestamp" forKey:@"timestamp"]; [enteredItem setObject:array forKey:@"items"]; [array addObject:enteredItem]; [array addObject:anotherDictionary]; [array addObject:moreDictionaries]; 所以在上面的例子中,我需要find包含@“我是一个id”的字典(并返回它)。 希望我的问题很清楚。 谢谢你尽你所能的帮助。

用另一个NSMutableArray对自定义对象sortingNSMutableArray

我有2个NSMutableArrays 。 第一个数组包含具有属性NSString *itemID自定义对象实例,第二个数组仅包含具有相同itemID值的NSString对象,但是以其他顺序包含。 我需要通过每个对象的itemID属性sorting第一个数组,它应该像第二个数组sorting。 我怎么能做到这一点?

如何创build一个NSMutableArray并为其指定一个特定的对象?

我只是进入Obj C,我正在创build一个MKAnnotations数组。 我已经创build了名为TruckLocation的MKAnnotation类,它包含名称,描述,纬度和经度。 这是我迄今为止的数组: NSMutableArray* trucksArray =[NSMutableArray arrayWithObjects: @[<#objects, …#>] nil];

:无法识别的select器发送到实例SIGABRT

我有这个代码试图在一个循环中运行一组简单的图像。 所有我在应用程序中是一个UIImageView在我的视图控制器的.h文件中声明: @property (strong, nonatomic) IBOutlet UIImageView *imageDisplay; 以下在我的.m文件的viewDidLoad方法中: NSMutableArray *imageView = [[NSMutableArray alloc] init]; [imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim1.png"]]]; [imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim2.png"]]]; [imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim3.png"]]]; [imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim4.png"]]]; [imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim5.png"]]]; [imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim6.png"]]]; [imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim7.png"]]]; imageDisplay.animationImages = imageView; imageDisplay.animationDuration = […]

我可以把不同types的对象放在同一个NSMutableArray?

我有A和Bclass 我可以把这些类放在同一个NSMutableArray中吗? 例: NSMutableArray *maincoll = [[NSMutableArray alloc] init]; ClassA *ca = [[classA alloc] init]; ClassB *cb = [[classB alloc] init]; //here is case [maincoll addObject:ca]; [maincoll addObject:cb]; …

是否有可能调剂addObject:在NSMutableArray中?

是否有可能改变NSMutableArray的addObject:方法? 这是我正在尝试。 #import <Foundation/Foundation.h> #import <objc/runtime.h> @implementation NSMutableArray (LoggingAddObject) + (void)load { Method addObject = class_getInstanceMethod(self, @selector(addObject:)); Method logAddObject = class_getInstanceMethod(self, @selector(logAddObject:)); method_exchangeImplementations(addObject, logAddObject); Method original = class_getInstanceMethod(self, @selector(setObject:atIndexedSubscript:)); Method swizzled = class_getInstanceMethod(self, @selector(swizzled_setObject:atIndexedSubscript:)); method_exchangeImplementations(original, swizzled); } – (void)logAddObject:(id)anObject { [self logAddObject:anObject]; NSLog(@"Added object %@ to array %@", anObject, self); } -(void)swizzled_setObject:(id)obj atIndexedSubscript:(NSUInteger)idx { NSLog(@"This […]

下标使用不明确

我有一个可扩展的表格,当点击一个可见的行时出现或消失的自定义单元格。 单元格的数据存储在plist中,并声明为NSMutableArray。 在下面的代码中,我得到了'下标模糊的使用'错误,并希望其他人遇到这个问题并且知道修正。 我已经尝试了所有可能的select,我必须补充一些有限的知识。 var cellDescriptors: NSMutableArray! func getCellDescriptorForIndexPath(indexPath: NSIndexPath) -> [String: AnyObject] { let indexOfVisibleRow = visibleRowsPerSection[indexPath.section][indexPath.row] let cellDescriptor = cellDescriptors[indexPath.section][indexOfVisibleRow] as! [String: AnyObject] return cellDescriptor } func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { let indexOfTappedRow = visibleRowsPerSection[indexPath.section][indexPath.row] if cellDescriptors[indexPath.section][indexOfTappedRow]["isExpanded"] as! Bool == true { // Ambiguous use of subscript error var shouldExpandAndShowSubRows = […]

iPhone / iOS如何在许多文件夹中加载大量图像并显示在表格视图中?

我讨厌的问题… 如果我有很多图像,我想把它加载到一个表格视图 并将文件名称显示为单元格文本,预览图像也显示在单元格中。 当我select单元格时,它会推到下一个视图,显示大尺寸的图像。 而已 。 我不知道如何将多个文件夹加载到数组? / ***********编辑*********** /这是我在里面设置了许多图像的文件夹 你可以看到只有一个根文件夹… 这是我的代码来加载内部的图像 NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Image"ofType:@""]; NSDirectoryEnumerator *direnum; direnum = [fileManager enumeratorAtPath: filePath]; imageFolder = [NSMutableArray new]; for(NSString *filename in direnum){ if([[filename pathExtension] isEqualToString:@"png"]){ [imageFolder addObject:filename]; } } NSLog(@"Files in the folder %@",imageFolder); 我得到这样的结果: Files in the folder […]

NSPredicate – 针对多个条件的大小写不敏感的过滤

我正在使用以下NSPredicate进行过滤, NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstName CONTAINS %@ ) OR (lastName CONTAINS %@ )OR (UserName CONTAINS %@ ) ", myText,myText,myText]; NSArray *filtered = [responseArray filteredArrayUsingPredicate:predicate]; 它工作正常,但是区分大小写。 我需要的过滤应该不区分大小写。 我试过了, NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(ANY firstName CONTAINS %@ ) OR (ANY lastName CONTAINS %@ )OR (ANY UserName CONTAINS %@ ) ", myText,myText,myText]; 但它会抛出错误 *** Terminating app due […]

如何比较2 nsarray

我有2个Nsarray,其中2个数组的对象是相同的,可能是对象的索引不同,但是它应该打印出来的都是相等的, NSArray *arr1 = [[NSArray alloc]initWithObjects:@"aa",@"bb",@"1",@"cc", nil]; NSArray *arr2 = [[NSArray alloc]initWithObjects:@"bb",@"cc",@"1",@"aa", nil]; if([arr1 isEqualToArray:arr2]) { NSLog(@"equal"); } else { NSLog(@"Not equal"); } 上面的代码打印“不相等”,但它应该打印“平等” ,我怎么能做到这一点