Iphone UITableViewCell未得到更新

Iphone UITableViewCell未得到更新,iphone,objective-c,cocoa,cocoa-touch,Iphone,Objective C,Cocoa,Cocoa Touch,对于“表视图”单元格中的每个条目,我需要在右侧有一个按钮,然后是一些文本,再在左侧有一个按钮。在按钮点击事件中,我需要更改文本(左/右按钮点击)并根据文本条件删除其中一个按钮。我无法使用cellForRowAtIndexPath方法删除按钮。我尝试对UITableViewCell进行子类化,并使用方法-prepareforeuse,但无法重置该单元格。有什么办法可以做到这一点吗?或者有什么方法可以使这个按钮不可见或隐藏 NSString *CellIdentifier = [[NSStr

对于“表视图”单元格中的每个条目,我需要在右侧有一个按钮,然后是一些文本,再在左侧有一个按钮。在按钮点击事件中,我需要更改文本(左/右按钮点击)并根据文本条件删除其中一个按钮。我无法使用cellForRowAtIndexPath方法删除按钮。我尝试对UITableViewCell进行子类化,并使用方法-prepareforeuse,但无法重置该单元格。有什么办法可以做到这一点吗?或者有什么方法可以使这个按钮不可见或隐藏

    NSString *CellIdentifier = [[NSString alloc] initWithFormat:@"Cell%d",indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}


[self.tableView clearsContextBeforeDrawing];
NSString *str = [listOfItems objectAtIndex:indexPath.row];

    cell.text = [listOfItems objectAtIndex:indexPath.row];
    cell.textColor = [UIColor blueColor];
    cell.font = [UIFont systemFontOfSize:14];

        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];       
        UIImage *image = [UIImage imageNamed:@"Arrow_Right.png"];
        CGRect frame = CGRectMake(290, 5, image.size.width, image.size.height);
        button.frame = frame;   
        [button setBackgroundImage:image forState:UIControlStateNormal];
        button.backgroundColor = [UIColor clearColor];
        [button addTarget:self action:@selector(rightArrow_clicked:) forControlEvents:UIControlEventTouchUpInside];
        [cell addSubview:button];

        UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];      
        UIImage *img = [UIImage imageNamed:@"Arrow_Left.png"];
        CGRect frame1 = CGRectMake(5, 5, img.size.width, img.size.height);
        button1.frame = frame1;
        [button1 setBackgroundImage:img forState:UIControlStateNormal];
        button1.backgroundColor = [UIColor clearColor];
        [button1 addTarget:self action:@selector(leftArrow_clicked:) forControlEvents:UIControlEventTouchUpInside];
        [cell addSubview:button1];

    if([str isEqual:@" abc  "])
        [button setEnabled:NO];
    if([str isEqual:@" pqr "])
        [button1 setEnabled:NO];

您要做的是创建UITableViewCell子类,并在
init
方法中添加子视图,以便只添加一次

最有可能发生的情况是,您正在将子视图添加到可重用单元中,该单元上很可能已经有以前使用过的按钮。此外,您可以将按钮设置为“不可见”,如下所示:


是的,它是一个可重复使用的电池。如何在-prepareforeuse方法中重置它?
[button setHidden:YES];