繁体   English   中英

如何加载单元格而不影响iOS中表视图的第一个单元格

[英]how to load cells without affecting the first cell of the table view in iOS

我是ios开发的新手,但我正在做这样的事情:我有一个表视图,我实现了显示日期选择器,当点击表视图的第一个单元格时[日期选择器将显示在第一个单元格下面]。 所以现在我想根据从日期选择器中选择的日期重新加载单元格,但不应重新加载整个表格视图,因为允许显示日期选择器的第一个单元格应始终存在。

所以我想用一些数据加载单元格而不影响第一个单元格。 我怎样才能做到这一点。 我有这样的想法:

如果我可以识别除第一个单元格之外的剩余单元格,那么我可以在我的cellForRowAtIndexpath方法中使用if条件,但我不知道如何识别剩余单元格。请有人帮助我。 我会把我的代码放在下面..

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


    UITableViewCell *cell;

    NSDate *today = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    // display in 12HR/24HR (i.e. 11:25PM or 23:25) format according to User Settings
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    NSString *currentTime = [dateFormatter stringFromDate:today];
    NSDate *date=[dateFormatter dateFromString:currentTime];



    if(indexPath.row==0){
        VCPerson *person = self.persons[indexPath.row];

        cell = [self createPersonCell:person];

    }

    else if ([self datePickerIsShown] && (self.datePickerIndexPath.row == indexPath.row)){

        // VCPerson *person = self.persons[indexPath.row -1];



        cell = [self createPickerCell:date];

    }




    if(indexPath.section!=0 && tapfirstCell) {

        UITableViewCell *cell = (UITableViewCell*)[self.tableView dequeueReusableCellWithIdentifier:kOtherCellIdentifier forIndexPath:indexPath];
        //cell.delegate_Dtepick = self;
        NSDictionary *dictionary = [_dataArray objectAtIndex:indexPath.section];
        NSArray *array = [dictionary objectForKey:@"data"];
        NSString *cellValue = [array objectAtIndex:indexPath.row];
        cell.textLabel.text =cellValue;

    }

    return cell;




   /*
    if ([self datePickerIsShown] && (self.datePickerIndexPath.row == indexPath.row)){

        // VCPerson *person = self.persons[indexPath.row -1];



        cell = [self createPickerCell:date];

    }



    else {

       // cellForDatePickCell* cell;
        VCPerson *person = self.persons[indexPath.row];

        cell = [self createPersonCell:person];
        //cell = [self createCustomCell:indexPath];
    }

    return cell;


 */




  }

在我的代码中,它没有显示我想要的第一个单元格后面的剩余单元格。 请有人帮助我。

编辑:这是我的全班

http://pastie.org/8993858

编辑2:

这是我需要做的一个例子..

在此输入图像描述

您的DatePicker应该在HeaderView中,而不是在TableViewCell中。

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (headerView == nil) 
        headerView = [[[HeaderView alloc] init] autorelease]; // further customizations
    return headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 30.0;
}

创建包含DatePicker的headerView或要添加到HeaderView的任何视图。 在重新加载tableView时,您只需返回已创建的headerView,并根据需要更新所有viewAtRows。 教程可以帮助您了解如何自定义HeaderView。

我只是有个主意。 您应该删除选择器行,然后插入所需的行。 使用以下两种方法来实现:

首先,显然调用[self.tableView deleteRowsAtIndexPaths:indexPath withRowAnimation:UITableViewRowAnimation]来删除选择器行。

然后在调用[self.tableView insertRowsAtIndexPaths:indexPath withRowAnimation:UITableViewRowAnimation] ,让表知道这一点。

当然,这不是全部工作,您必须正确处理UITableView数据源以符合这种情况(numberOfRowsAtIndexPath,cellForRowAtIndexPath ...应该返回适​​当的结果)。

全在这里: Apple Docs

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM