2012-07-24 25 views
0

我正在開發一個iOS應用程序的iOS 5和Im stucked陣列問題。我有一個自定義的類,我稱之爲人員。人員由兩個數組組成。一個給男孩,一個給女孩。首先,我想用另一個類的方法來填充Persons對象,而且我很確定這是適合的。但是當我要將代碼中的Persons對象分解爲單個數組時,它不起作用。它感覺就像Persons對象,或者它的數組以某種方式被阻塞。請幫忙。此代碼扔我看起來像一個錯誤:2012-07-24 09:29:03.073 PersonApp[4375:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary Boys]: unrecognized selector sent to instance 0x6ac0fe0'NSInvalidArgumentException當使用NSArray

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]; 

回答

1

什麼是[comm getPersons]返回?我認爲這不是「人」的對象。試試這個代碼。

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

這似乎是正確的課程。 – parek 2012-07-24 07:41:10

0

........我可能是錯在這裏,

,但你嘗試過類似

NSArray *boys = [[[NSArray alloc] initWithArray[[comm getPersons]boys]autorelease]; 

我很抱歉它是一個幾個星期,因爲我」 ve最後有Xcode打開,所以對任何代碼錯誤致歉,

你正在初始化/分配內存到NSArray,做一些像

NSLog(@"count %d",[[[comm getPersons]boys]count]); 

這至少應該告訴你,男孩數組存在,(假設它已經創建)...

的NSLog是你最好的朋友,我也建議學習如何使用調試器。