2

我在表格视图中有一个表格视图和 4 个部分。在第一部分中,我只有一行,在这个房间内我添加了一个文本字段。我为第一个单元格分配了一个自定义类。对于所有其他部分和行,我分配了第二类。但问题是当我在第一个单元格的文本字段中输入内容时。我checkaccessorytype检查了其他单元格并滚动表格。然后文本字段文本完成并且单元格附件也更改了这是代码

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

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

{
    if (section ==0)
    {
        return  1;
    }


    if (section ==1)
    {
        return  [filterObj.priceName count];
    }


    if (section ==2)
    {
        return  [filterObj.typeName count];
    }

    if (section ==3)
    {
        return  [othersArray count];
    }



    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *kCellID = @"DefaultCell";
     static NSString *kCellTwoID = @"tblCell";
    CustomCellWithTF *cell = (CustomCellWithTF *) [tableView dequeueReusableCellWithIdentifier:kCellID];
     customCellTwo *cellTwo = (customCellTwo *) [tableView dequeueReusableCellWithIdentifier:kCellTwoID];
    if(cell == nil)
    {
        NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"custonCell" owner:self options:nil];
        cell = (CustomCellWithTF *)[nibs objectAtIndex:0];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.font = [UIFont systemFontOfSize:12];
        cell.accessoryType = UITableViewCellStyleDefault;

    }

    if(cellTwo == nil)
    {


        NSArray *nibsTwo = [[NSBundle mainBundle] loadNibNamed:@"customCellTwo" owner:self options:nil];
        cellTwo = (customCellTwo *)[nibsTwo objectAtIndex:0];
        cellTwo.selectionStyle = UITableViewCellSelectionStyleNone;
        cellTwo.textLabel.font = [UIFont systemFontOfSize:12];
        cellTwo.accessoryType = UITableViewCellStyleDefault;
    }

    if (indexPath.section == 0 && indexPath.row == 0)
    {
        cell.textLabel.text = @"Location";
        location = [[UITextField alloc] initWithFrame:CGRectMake(130, 10, 150, 25)];
        [location setBorderStyle:UITextBorderStyleRoundedRect];
        location.delegate = (id)self;
        [cell addSubview:location];
        return cell;
    }

    if (indexPath.section == 1)
    {

        cellTwo.textLabel.text = [filterObj.priceName objectAtIndex:indexPath.row];


    }

    if (indexPath.section == 2)
    {
        cellTwo.textLabel.text = [filterObj.typeName objectAtIndex:indexPath.row];

    }

    if (indexPath.section == 3)
    {
        cellTwo.textLabel.text =[othersArray objectAtIndex:indexPath.row];

    }



    return cellTwo;






}

请告诉我如何解决这个问题

4

2 回答 2

0

每当cellForRowAtIndexPath:执行 table get scrolled 方法时,您必须全局设置值,然后将其设置到方法中的文本字段中cellForRowAtIndexPath:,您的问题将得到解决。

于 2013-04-26T12:14:40.920 回答
0

更新:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *kCellID = @"DefaultCell";
         static NSString *kCellTwoID = @"tblCell";
        CustomCellWithTF *cell = (CustomCellWithTF *) [tableView dequeueReusableCellWithIdentifier:kCellID];
         customCellTwo *cellTwo = (customCellTwo *) [tableView dequeueReusableCellWithIdentifier:kCellTwoID];
        if(cell == nil)
        {
            NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"custonCell" owner:self options:nil];
            cell = (CustomCellWithTF *)[nibs objectAtIndex:0];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.textLabel.font = [UIFont systemFontOfSize:12];
            cell.accessoryType = UITableViewCellStyleDefault;
    if (indexPath.section == 0 && indexPath.row == 0)
        {
            cell.textLabel.text = @"Location";
            location = [[UITextField alloc] initWithFrame:CGRectMake(130, 10, 150, 25)];
            [location setBorderStyle:UITextBorderStyleRoundedRect];
            location.delegate = (id)self;
            [cell addSubview:location];
            return cell;
        }
        }

        if(cellTwo == nil)
        {


            NSArray *nibsTwo = [[NSBundle mainBundle] loadNibNamed:@"customCellTwo" owner:self options:nil];
            cellTwo = (customCellTwo *)[nibsTwo objectAtIndex:0];
            cellTwo.selectionStyle = UITableViewCellSelectionStyleNone;
            cellTwo.textLabel.font = [UIFont systemFontOfSize:12];
            cellTwo.accessoryType = UITableViewCellStyleDefault;
if (indexPath.section == 1)
        {

            cellTwo.textLabel.text = [filterObj.priceName objectAtIndex:indexPath.row];


        }

        if (indexPath.section == 2)
        {
            cellTwo.textLabel.text = [filterObj.typeName objectAtIndex:indexPath.row];

        }

        if (indexPath.section == 3)
        {
            cellTwo.textLabel.text =[othersArray objectAtIndex:indexPath.row];

        }
        }


        return cellTwo;
    }
于 2013-04-26T11:22:54.480 回答