objective-c - 使用 NSArray 时出现 NSInvalidArgumentException

标签 objective-c ios xcode ios5

我正在为 iOS 5 开发 iPhone 应用程序,但遇到了数组问题。我创建了一个自定义类,将其称为“Persons”。 Persons 由两个数组组成。一套给男孩,一套给女孩。首先,我想使用另一个类中的方法填充 Persons 对象,并且我非常确定这可以正常工作。但是,当我要将代码中的 Persons 对象的数组拆分为单个数组时,它不起作用。感觉就像 Persons 对象或其数组以某种方式卡住了。请帮忙。此代码向我抛出一个错误,如下所示: 2012-07-24 09:29:03.073 PersonApp[4375:f803] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFDictionary Boys” ]: 无法识别的选择器发送到实例 0x6ac0fe0'

Persons.h

#import <Foundation/Foundation.h>

@interface Persons : NSObject {
    NSArray *Boys;
    NSArray *Girls;
}

@property (nonatomic, copy) NSArray *Boys;
@property (nonatomic, copy) NSArray *Girls;

@end

PersonsViewController.h

#import <UIKit/UIKit.h>
#import "Persons.h"

@interface PersonsViewController : UITableViewController

@property (nonatomic, strong) Persons *persons;

@end

PersonsViewController.m

#import "PersonsViewController.h"

NSArray *boys;
NSArray *girls;
...................
@synthesize persons;     
...................
Communication *comm = [[Communication alloc] init];    
self.persons = [comm getPersons];
boys = [self.persons Boys];
girls = [self.persons Girls];

最佳答案

[comm getPersons] 返回什么?我认为这不是“Persons”对象。试试这个代码。

if ([[comm getPersons] isKindOfClass:[Persons class]])
{
   NSLog(@"Not returning Persons object. So this is the error!");
}

关于objective-c - 使用 NSArray 时出现 NSInvalidArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11626094/

相关文章:

ios - 框架CFBundleIdentifier冲突

iphone - ios:使 UIBarButtonItem 与 TabBar 导航交互

objective-c - 将属性字符串中的正则表达式匹配替换为 Objective-C 中的图像

html - 让图像以移动页面 View 为中心

ios - Xcode 不允许我对 UIView 使用 NSObject 的 init() 函数

iOS:使用CGContextAddLineToPoint绘制多条线

objective-c - 由于文本标签而导致 UICollectionView 滚动不稳定

iphone - resignFirstResponder 出现后续处理问题(键盘在 iPhone 5 上被阻止或崩溃)

ios - 在 iOS 7.1 上测试应用

ios - ReactiveCocoa 3 : Map signal to value (Swift)