0

iOS 5 用の iPhone アプリケーションを開発していて、アレイの問題で立ち往生しています。Persons というカスタム クラスを 1 つ作成しました。Persons は 2 つの配列で構成されます。男の子用と女の子用です。まず、別のクラスのメソッドを使用して 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'

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

2 に答える 2

1

[comm getPersons] は何を返しますか? 「Persons」オブジェクトではないと思います。このコードを試してください。

if ([[comm getPersons] isKindOfClass:[Persons class]])
{
   NSLog(@"Not returning Persons object. So this is the error!");
}
于 2012-07-24T07:34:30.097 に答える
0

........私はここで間違っている可能性があります、

しかし、あなたは次のようなことを試しましたか

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

Xcodeを最後に開いてから数週間が経ちました。コードの間違いをお詫びします。

NSArrayにメモリを初期化/割り当てていますか?

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

これは、少なくとも男の子の配列が存在することを示しているはずです(作成されていると仮定して)...

NSLogはあなたの親友です。デバッガーの使い方を学ぶこともお勧めします。

于 2012-07-25T15:19:46.710 に答える