0

私のアプリケーションでは、アイテムを表示します。私のJSONフィードには 50 個のアイテムが含まれていますが、最初に 25 個を表示したいと考えており、ユーザーが最後の行までスクロールすると、さらにアイテムをロードする必要があります。

私がやっている:

JSONフィードのダウンロード;

NSString *jsonString = [NSString 
                        stringWithContentsOfURL:[NSURL URLWithString:xmlDataUrl] 
                        encoding:NSStringEncodingConversionAllowLossy
                        error:nil];
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *results = [parser objectWithString:jsonString error:nil];
parser = nil;
[self setTableData:[results objectForKey:@"feed"]];

///

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

///

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        // Return the number of rows in the section.
        //return [tableData count];
        return 25;
    }

そして最後の行を検出します:

   if(indexPath.row == [self.tableData count] - 1) 
    {

        NSLog(@"Last Row");
    }

しかし、最後の行を検出していません。これは、ダウンロードしている JSON に 25 行を超える行が含まれているためですか?

そして、どうすれば新しい行を追加[self.tableDate count] +1;できますか?

返さ[tableData count];れた場合、最後の行を検出していますが、行はすでに 100% 埋められています。+1 よりも 25/50 を表示する必要があります。

4

1 に答える 1

2

コードの 2 番目のブロックをどこで呼び出していますか? それはあなたのテーブル デリゲートの willDisplayCell: メソッドにありますか?

私のプロジェクトの1つに、非常によく似たコードがあります

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == self.search.count && [tableView.indexPathsForVisibleRows containsObject:indexPath])
    {
        [self.search findMoreStuff];
    }
}

self.search 用に作成された行の後に余分な行が追加されているので、私の場合は self.search.count をチェックしていますが、おそらく self.search.count-1 を見たいと思うでしょう。

于 2012-04-13T20:58:51.260 に答える