1

私は本当に助けが必要です...

NSMutableArrayを使用してセクションのセル数を取得しようとすると、[__ NSCFString count]:認識されないセレクターがインスタンス0x6d567e0に送信されます。

これは、「rows = [[searchProfile objectAtIndex:section]count];」を使用すると発生します。

コードは次のとおりです。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSLog(@"1");
    // _________ Return the number of sections ________
    int sections =  0;

    if (tableView == self.tableView)
    {
        sections = 2;
    }
    if (tableView == self.searchDisplayController.searchResultsTableView)
    {
        sections = [searchedProfile count];
    }
    return sections;
}


/* ------------------------------------------ Set The Number Of Cells for Each Section ------------------------------- */


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"2");

    // _________  Return the number of rows in the section. ________
    int rows = 0;

    if (tableView == self.tableView)
    {
        if (section == 0) {
            rows = userProfile.count;}
        else {
            rows = profiles.count;}
    }

    if (tableView == self.searchDisplayController.searchResultsTableView)
    {
        rows = [[searchedProfile objectAtIndex:section]count];
    }
    return rows;
}

そして、文字列を「searchedProfile」配列に挿入するメソッド:

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    searchedKeys = [NSMutableArray array];
    searchedProfile = [NSMutableArray array];
    searchedData = [NSMutableDictionary dictionary];

    [searchedProfile removeAllObjects];
    [searchedData removeAllObjects];
    [searchedKeys removeAllObjects];


        NSDictionary *profile;

        for (profile in profiles)
        {
            NSString *birthname;
            NSString *currentname;
            NSString *photopath;
            NSDate *birthdate;

            for (birthname in profile)
            {
                birthname = [profile objectForKey:@"birthname"];
                currentname = [profile objectForKey:@"currentname"];
                photopath = [profile objectForKey:@"profilepic"];
                birthdate = [profile objectForKey:@"birthdate"];
                NSRange nameRange = [birthname rangeOfString:searchString options:NSCaseInsensitiveSearch];

                if (nameRange.location != NSNotFound)
                {
                    [searchedProfile addObject:birthname];
                    [searchedData setObject:birthname forKey:@"birthname"];
                    [searchedData setObject:currentname forKey:@"currentname"];
                    [searchedData setObject:photopath forKey:@"profilepic"];
                    [searchedData setObject:birthdate forKey:@"birthdate"];
                    if ([birthname isEqualToString:[profile objectForKey:@"birthname"]])
                        break;
                }
            }
        }
    NSLog(@"SEARCHED PROFILES: %@", searchedProfile);
    NSLog(@"SEARCHED DATA:%@", searchedData);
    NSLog(@"SEARCHED KEYS:%@", searchedKeys);
    NSLog(@"count test: %d", searchedProfile.count);
    return YES;
}

ありがとうございました !

4

3 に答える 3

5

countNSStringでNSArrayのメソッドを使用しているようですが、これは許可されていません。NSStringsを配列searchedProfileに格納すると、文字列の長さを調べたいように見えます。したがって、これの代わりに:

    rows = [[searchedProfile objectAtIndex:section] count];

これを行う:

    rows = [[searchedProfile objectAtIndex:section] length];
于 2012-09-08T01:56:42.530 に答える
0

[searchedProfile objectAtIndex:section]は、searchedProfileのオブジェクトが文字列であるため、文字列を返します。これは、以前にオブジェクトを追加した方法であるためです。

 [searchedProfile addObject:birthname];

countはNSStringに定義されたプロパティではありません。とにかく、オブジェクトの数(つまり、searchedProfile配列に格納されている誕生名の数)をテーブルの行数として返したいようです。これを試してください

rows = [searchedProfile count];
于 2012-09-08T02:07:50.143 に答える
0

次のようにして「searchedProfile」配列を保持します。searchedProfile=[[NSArrayarray] hold];

于 2012-09-08T03:58:00.427 に答える