1

それが私の最初の質問です。

私の UITableView は、作成されたすべてのセルを表示しません。どうしたの?

アプリが起動された後、サーバーからデータをダウンロードし、UITableView を使用して表示します。UITableView をスクロールすると、アプリはより多くのデータをダウンロードします (Twitter アプリなど)。そして、すべてがうまく表示されます。

しかし、UISearchBar もあります。そして、問題があります。SearchBar がアクティブな場合、すべてが同じように機能します (たとえば、入力中にデータの最初の部分をダウンロードし、スクロール中に別の部分をダウンロードします) が、UITableView はデータの最初の部分のみを表示します。

しかし、 cellForRowAtIndexPath の NSLog は、すべてのセルが問題なく作成されていることを示しています。そして、私はそれをどうするかわかりません。

私の英語で申し訳ありませんが、あまり上手ではありません。

また、numberOfRowsInSection は正しい値 (たとえば 3) を返しますが、UITableView には 1 つのセルしか表示されません。もちろん、私の配列には、表示する必要があるすべてのデータが含まれています。

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        if(searching == 0){ //if we aren't in search
            NSLog(@"Total rows %d", ids.count);
            return [ids count];
        }
        if(searching == 1){ //if we are in search
            NSLog(@"Total rows %d", idsSearch.count);
            return [idsSearch count];
        }
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            }
        }

        NSInteger row = [indexPath row];

        if(searching == 0){
            cell.textLabel.text = [names objectAtIndex:row];
            NSLog(@"Cell with %@ created", [names objectAtIndex:row]);
        }

        if(searching == 1){
            cell.textLabel.text = [namesSearch objectAtIndex:row];
            NSLog(@"Cell with %@ created", [namesSearch objectAtIndex:row]); //tells me that ALL cells were created. But they aren't in UITableView.
        }

        return cell;
    }

    - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
        searchRequest = searchBar.text;
        if([searchRequest isEqualToString:@""]){
            searching = 0;
        }
        else{
            searching = 1;

            [idsSearch removeAllObjects];
            [namesSearch removeAllObjects];

            [self getArtistsStartFrom:0 withLimit:1]; //downloads new data (1 record in this example) with needed predicate (searchRequest) from server, then adds it to arrays and performs [self.tableView reloadData] at the end.
        }
    }
4

0 に答える 0