-1

一連のコア データを格納する array と呼ばれるカスタム オブジェクトの配列があります。この配列を使用して、UITableView にデータを入力し、セルを作成します。次に、UISearch を開いたときに同じ配列を使用しようとしましたが、この時点で配列は空です。どうすれば配列内のオブジェクトを保持できますか?

編集

わかりました、ここに私のコードの一部があります

私の.hファイル

@interface SelectCourses : UIViewController <DataHandlerDelegate, UITableViewDataSource, UITableViewDelegate, UITableViewDataSource> {
DataHandler *dataHandler;
NSMutableArray *courses;
IBOutlet UITableView *table;
IBOutlet UISearchBar *searchFilter;
//NSMutableArray *filteredCourses;
BOOL isFiltered;
}

@property (retain) NSMutableArray* filteredCourses;

それから私の.mファイル、私は無関係だと思われるいくつかの関数を省略しました

@implementation SelectCourses

@synthesize Delegate;
@synthesize filteredCourses;
...
...

- (void) dataHandlerHasLoadedCourseData:(NSMutableArray *)courseData {
courses = courseData;
[table reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(isFiltered){
    return filteredCourses.count;
}
if (courses) {
    NSLog(@"Count: %i", [courses count]);
    if (courses.count == 1) {
        return 0;
    }
    return [courses count];
}
else
    return 0;
}
...
...
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchFiltert { 
NSLog(@"searchBarSearchButtonClicked");//More debugging

if(searchFilter.text.length == 0)
{
    isFiltered = FALSE;
}
else
{
    NSLog(@"%@", [NSString stringWithFormat:searchFilter.text]);
    isFiltered = true;


    for (Course *course in courses) 
    {
        NSRange codeRange = [course.Code rangeOfString:searchFilter.text options:NSCaseInsensitiveSearch];
        NSRange nameRange = [course.Name rangeOfString:searchFilter.text options:NSCaseInsensitiveSearch];
        if(codeRange.location != NSNotFound || nameRange.location != NSNotFound)
        {
            [filteredCourses addObject:course];
        }
    }
}
[table reloadData];
}

スクリプトを実行すると、まだ次のエラーが発生します。配列が空であることが原因であると単純に想定しました

2012-04-11 20:54:23.067 scheduleTable[45885:fb03] -[__NSArrayM Code]: unrecognized selector sent to instance 0x897b360
2012-04-11 20:54:23.068 scheduleTable[45885:fb03] *** WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate: <NSInvalidArgumentException>     -[__NSArrayM Code]: unrecognized selector sent to instance 0x897b360

私の course.h と .m は次のようになります

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@class Post;

@interface Course : NSManagedObject

@property (nonatomic, retain) NSString *Code;
@property (nonatomic, retain) NSString *Name;
@end

#import "Course.h"
#import "Post.h"

@implementation Course

@synthesize Code;
@synthesize Name;
@end
4

2 に答える 2

0

私があなたの質問を正しく理解している場合、配列を保持するには、次のように.hファイルで配列を宣言します。 @property (retain) NSMutableArray *yourArrayName;

次に、次のように.mファイルで合成します。 @synthesize yourArrayName;

于 2012-04-11T03:03:29.653 に答える