Iphone iOS表视图中的单元格重用和行选择

Iphone iOS表视图中的单元格重用和行选择,iphone,uitableview,customization,Iphone,Uitableview,Customization,我必须创建具有行和节组合的表视图,并使用按钮自定义节I的行 现在任务只有一行,点击按钮后,每个部分都应该选择一行 我的代码工作受到了打击,而问题的解决是 当点击一个特定部分行的按钮,另一个部分行的按钮显示选择时,我认为单元格重用性问题 当我点击特定按钮时,如何对同一部分的rest按钮执行删除过程 这是我的密码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)i

我必须创建具有行和节组合的表视图,并使用按钮自定义节I的行

现在任务只有一行,点击按钮后,每个部分都应该选择一行

我的代码工作受到了打击,而问题的解决是

  • 当点击一个特定部分行的按钮,另一个部分行的按钮显示选择时,我认为单元格重用性问题

  • 当我点击特定按钮时,如何对同一部分的rest按钮执行删除过程

  • 这是我的密码

    - (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];
        }
    
        self.juju=[[NSMutableArray alloc]init];
    
        NSArray *listSeprately = [[NSArray alloc]init];
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"questionid==%d",indexPath.section+1];
    
        listSeprately = [self.questAnswer filteredArrayUsingPredicate:predicate];
    
        self.buttonMe=[[UIButton alloc]init];
        self.buttonMe = [UIButton buttonWithType:UIButtonTypeCustom];
    
        [self.buttonMe setFrame:CGRectMake(260.0, 7.0, 30.0, 30.0)];
    
        self.buttonMe.tag=i;
    
        if([[arrayCheckUnchek objectAtIndex:indexPath.row] isEqualToString:@"Uncheck"])
        {
            [self.buttonMe setImage:[UIImage imageNamed:@"check.gif"] forState:UIControlStateNormal];
        }
        else
        {
            [self.buttonMe setImage:[UIImage imageNamed:@"uncheck.jpg"] forState:UIControlStateNormal];
        }
    
        [self.buttonMe addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
        cell.textLabel.text=[juju objectAtIndex:indexPath.row];
    
        [cell.contentView addSubview: self.buttonMe];
    
        i++;
    
        return cell;
    }
    
    当我们点击任何按钮时,这个代码调用

    -(void)buttonClicked:(id)sender
    {
        CGPoint touchPoint = [sender convertPoint:CGPointZero toView:self.tableView ];
    
        NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touchPoint];
    
        // No need to use tag sender will keep the reference of clicked button
    
        self.buttonMe = (UIButton *)sender;
    
        //Checking the condition button is checked or unchecked.
        //accordingly replace the array object and change the button image
    
        if([[arrayCheckUnchek objectAtIndex:indexPath.row] isEqualToString:@"Uncheck"])
        {
            [ self.buttonMe setImage:[UIImage imageNamed:@"checkImage.jpg"] forState:UIControlStateNormal];
            [arrayCheckUnchek replaceObjectAtIndex:indexPath.row withObject:@"Check"];
        }
        else
        {
            [ self.buttonMe setImage:[UIImage imageNamed:@"uncheck.jpg"]   forState:UIControlStateNormal];
            [arrayCheckUnchek replaceObjectAtIndex:indexPath.row withObject:@"Uncheck"];
        }
    
        [self.tableView reloadData];
    }
    
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        self.arrayCheckUnchek = [[NSMutableArray alloc]init];
        self.questAnswer=//here i hve records store that is 19
    
        for(int i=0; i<[self.questAnswer count]; i++)
        {
            [arrayCheckUnchek addObject:@"Uncheck"];
        }
    }
    
    -(无效)按钮点击:(id)发件人
    {
    CGPoint-touchPoint=[sender-convertPoint:CGPointZero-toView:self.tableView];
    NSIndexPath*indexPath=[self.tableView indexPathForRowAtPoint:touchPoint];
    //无需使用标记发送器,将保留已单击按钮的引用
    self.buttonMe=(UIButton*)发送方;
    //选中或取消选中“条件”按钮。
    //相应地替换数组对象并更改按钮图像
    if([[arrayCheckUnchek objectAtIndex:indexath.row]isEqualToString:@“取消选中”])
    {
    [self.buttonMe setImage:[UIImage ImageName:@“checkImage.jpg”]用于状态:UIControlStateNormal];
    [arrayCheckUnchek replaceObjectAtIndex:indexath.row with object:@“Check”];
    }
    其他的
    {
    [self.buttonMe setImage:[UIImage ImageName:@“uncheck.jpg”]用于状态:UIControlStateNormal];
    [arrayCheckUnchek replaceObjectAtIndex:indexath.row with object:@“取消选中”];
    }
    [self.tableView重载数据];
    }
    -(无效)viewDidLoad
    {
    [超级视图下载];
    self.arrayCheckUnchek=[[NSMutableArray alloc]init];
    self.questAnswer=//这里我有一个19的记录存储
    对于(int i=0;i您可以在didSelectRowAtIndexPath:method下的值中保留索引([indexPath行])。然后您可以在返回cellForRowAtIndexPath:method之前检查[indexPath行]是否等于下的值。在进行检查后,可以添加如下块:

    if (match) {
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
        }
        else {
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
    }
    

    我希望这对您有所帮助。

    您为什么使用I++;?tableview自动递增无需使用I++?是否有解决方案?您使用了最差的格式。我已经尽可能多地编辑了。请检查拼写和语法,以便有人能理解。我没有为选择添加复选标记,我添加了按钮,这不会对您造成任何影响