1

メインテーブルビューのカスタムセルを作成することにより、テーブルビューの各セルにテーブルビューがあります。問題は、最初のものを除くすべてのインデックスパスのテーブルビュー コンテンツを表示できることです。テーブルビューをスクロールして最初のセルを画面外に出し、最初のセルをスクロールして戻すと、最初のセルのコンテンツが表示されます。

以下の私のコードを見つけてください

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [itemArray 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];
        cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];
    }
    for (int i=0; i<[itemArray count]; i++) {
        ////NSLog(@"row is %d",i);
        if (indexPath.row==i) {
            cell.textLabel.text=[itemArray objectAtIndex:i];
        }
    }
    return cell;
}

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

なぜそれが起こっているのか誰にも教えてもらえますか。最初のセルの内容も画面に表示したい。

4

2 に答える 2

1
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [itemArray 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];
        cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];
    }
    // why are you using this code in for loop ??
    /*
    for (int i=0; i<[itemArray count]; i++) {
        ////NSLog(@"row is %d",i);
        if (indexPath.row==i) {
            cell.textLabel.text=[itemArray objectAtIndex:i];
        }
    }
    */
    cell.textLabel.text=[itemArray objectAtIndex:indexPath.row];
    return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
于 2013-08-30T12:14:28.053 に答える
0

以下のメソッドを以下のように更新してください。それはあなたを助けるかもしれません。にオブジェクトを追加した後、テーブルビューをリロードしていることを確認してくださいitemArray

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";
// add a placeholder cell while waiting on table data
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
    }
    cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
    cell.textLabel.numberOfLines = 1;
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];
    cell.textLabel.text=[[[DataManager GetInstance]getCurrentTableContent] objectAtIndex:indexPath.row];
}

return cell;
于 2013-08-30T07:45:45.923 に答える