0

PHPを使用してMySQLデータベースの最初の25項目を取得するXMLを解析しています-LIMITとGET。テーブルビューの下部に追加する[さらに読み込む]セルをクリックすると、次の25個のアイテムが正常に取得されますが、最初の40個のみが読み込まれ、最後の10個は省略されます。[さらに読み込む]をクリックするたびに"セルは私の範囲に25を追加します(つまり、0-25,25-50)が、私の範囲は65で上限があり、ディスプレイは40で上限があるようです。

これが私のロードモア機能で機能していません:

-(void) getNewRange{
    int currentRange = [allItems count];
    int newRange = currentRange + 25;

    if(newRange > [xmlParser total]){
        NSLog(@"evaluating as greater than the total, which is 837");
        newRange = [xmlParser total];
    }

    NSString *range = [[NSString alloc] initWithFormat:@"?range=%d&range2=%d",currentRange,newRange];
    NSString *newUrl =[[NSString alloc] initWithFormat:@"http://localhost/fetchAllTitles.php%@",range];

    XMLParser *tempParser = [[XMLParser alloc] loadXMLByURL:newUrl];
    [allItems addObjectsFromArray:[tempParser people]];
    NSMutableArray *newCells = [[NSMutableArray alloc] initWithCapacity:25];

    for(int i=currentRange;i<newRange;i++){
        NSLog(@"%d",i);
         NSIndexPath *indexpath=[NSIndexPath indexPathForRow:i inSection:0];
        [newCells addObject:indexpath];
    }

    NSLog(@"%@",newUrl);

    [self.tableView insertRowsAtIndexPaths:newCells withRowAnimation:UITableViewRowAnimationAutomatic];
}

近づいていますが、次の新しいエラーが発生します。

*** Assertion failure in -[_UITableViewUpdateSupport _computeRowUpdates], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableViewSupport.m:386
4

3 に答える 3

4

テーブルビューのセルを再利用する方法を確認してください。

データはセルによって「所有」される必要はありません。

于 2012-08-24T20:14:28.253 に答える
3

UITableViewはデータを含むクラスではないため、表示するセルを直接マイクロ管理しようとしないでください。別のポスターが述べたように、それを使用する方法を読んでください。あなたがすべきことは:

-(void)loadNewData
{
    NSIndexPath *index;
    XMLParser *tempParser = [[XMLParser alloc] loadXMLByURL:newUrl];
    NSArray *people=[tempParser people];
    for(id *person in people)
    {
        [self.dataArray addObject:person];
        indexPath=[NSIndexPath indexPathForRow:[self.dataArray indexForObject:person] inSection:0];
        [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath withRowAnimation:UITableViewRowAnimationAutomatic];
    }
}

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [AnArray count];//use whatever array stores your data
}


//If you've subclassed the cell, adjust appropriately.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    //Customize the cell
    return cell;
}

テーブルビューは、セルの表示に関連するすべてのロジックを処理します。このように、常にメモリを占有するセルの数は限られており、それを処理する必要はありません。テーブルビューは、セルの再利用を自動的に処理し、/の前にバッファとして必要なセルの数を認識します。後。

于 2012-08-24T20:49:11.867 に答える
2

メソッド内にnumberOfRowsInSectionを設定しないでください。行数は、tableViewのデータソースメソッドから返される必要があります- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section。そこに戻っ[allItems count]てください。

于 2012-08-24T20:20:18.637 に答える