簡體   English   中英

上一節超出屏幕時,iPhone的UITableView部分

[英]UITableView section when previous section is out of screen iPhone

我正在開發iPhone應用程序,但在檢查分組表視圖的部分時遇到了一些麻煩。 當由於我向下滾動tableview並且tableview彈回而不再顯示第一部分時,第二部分從第一部分獲取設置嗎? 我用indexPath.section值檢查它是哪一部分。 我該如何解決? 抱歉,如果我的英語不正確!

對不起,缺少代碼! 這是cellForRowAtIndexPath代碼的一部分:

    - (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(indexPath.section == 0){
        pinSwitch.hidden = YES;
    cell.imageView.image = [UIImage imageNamed:@"test_item.png"];
    if([headarray count] != 0){
        if(indexPath.row > [headarray count] - 1){
            cell.imageView.alpha = 0;
            cell.textLabel.text = [NSString stringWithFormat:@"Add new",indexPath.row + 1];

        }
        else{
            cell.imageView.alpha = 1;
            NSArray *infoarray = [headarray objectAtIndex:indexPath.row];
            cell.textLabel.text = [infoarray objectAtIndex:0];
        }
    }
}
    else if(indexPath.section == 1){


    if(indexPath.row == 0){
//some more cell data
}

我認為這足以顯示我的問題!

粘貼用於生成單元的代碼,看來您未正確使用重用單元機制

編輯:代碼不完整,我認為你應該做這樣的事情:

- (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(indexPath.section == 0){
        pinSwitch.hidden = YES;
    cell.imageView.image = [UIImage imageNamed:@"test_item.png"];
    if([headarray count] != 0){
        if(indexPath.row > [headarray count] - 1){
            cell.imageView.alpha = 0;
            cell.textLabel.text = [NSString stringWithFormat:@"Add new",indexPath.row + 1];

        }
        else{
            cell.imageView.alpha = 1;
            NSArray *infoarray = [headarray objectAtIndex:indexPath.row];
            cell.textLabel.text = [infoarray objectAtIndex:0];
        }
    }
}
    else if(indexPath.section == 1){
        if(indexPath.row == 0){
  // you should fill cell data for all cases !!!!  
  }
} else { // for example
            cell.imageView.alpha = 1;
            NSArray *infoarray = [headarray objectAtIndex:indexPath.row];
            cell.textLabel.text = [infoarray objectAtIndex:0];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM