Ios 当视图重新加载时,在自定义单元格中保持标签的常量值,当第二次执行操作时更改值更改标签值?

Ios 当视图重新加载时,在自定义单元格中保持标签的常量值,当第二次执行操作时更改值更改标签值?,ios,objective-c,uitableview,uilabel,custom-cell,Ios,Objective C,Uitableview,Uilabel,Custom Cell,这个问题可能会被问到不同的方式,但我的情况是另一种方式,所以在设置重复检查此。从根视图我调用右视图,右视图有一些选项,当我按下一行时,自定义单元格标签值应更改为我所做的其他值。但当我再次调用根视图和右视图时,标签值变为原始值,那么在视图重新加载时如何保持自定义单元格标签值的相同值 最初,am为标签赋值为 (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPa

这个问题可能会被问到不同的方式,但我的情况是另一种方式,所以在设置重复检查此。从根视图我调用右视图,右视图有一些选项,当我按下一行时,自定义单元格标签值应更改为我所做的其他值。但当我再次调用根视图和右视图时,标签值变为原始值,那么在视图重新加载时如何保持自定义单元格标签值的相同值

最初,am为标签赋值为

(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row==0)
        {
            cell.rightpanelLabel1.text=@"Switch to Photo View";
        } 
}
然后当细胞压榨发生时,我改变了标签值,就像这样

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell=[[ViewProfileRightPanelCell alloc]init];
     static NSString *cellidentifier=@"ViewProfileRightPanelCell";
    cell=(ViewProfileRightPanelCell*)[tableView dequeueReusableCellWithIdentifier:cellidentifier];
    for (cell in [ViewProfileRightPanelTableView subviews])
    {
        if ([cell isKindOfClass:[ViewProfileRightPanelCell class]])
        {
            if (cell.tag == indexPath.row)
            {

                if ([cell.rightpanelLabel1.text isEqualToString:@"Switch to Photo View"] )
                {
                    cell.rightpanelLabel1.text=@"Switch to List View";
                }

            }
        }
    }
}

如何在视图再次加载时保持相同的值,但另一个条件是,如果我再次按下单元格,它将更改为以前的值,并且正在使用自定义单元格

您正处于一个良好的轨道上-您有自定义单元格,这非常有帮助

为自定义单元格创建其他属性:

@property (nonatomic, retain) NSString* selectedText;
@property (nonatomic, retain) NSString* deselectedText;
@property (nonatomic, assign) BOOL selected;
在cellForRowAtIndexPath中创建单元格时:初始化两个文本:

if(indexPath.row==0)
{
    cell.selectedText= @"Switch to Photo View";
    cell.deselectedText = @"Switch to List View";
    cell.selected = NO;
} 
以及:

并在自定义单元格上为“selected”属性创建自定义setter


k我会再试一次,我会通知你,但在加载标签的初始值时有疑问,应该切换到照片视图。你的意思是什么?“这有什么问题吗?”选择了属性(非原子,assingn);当我运行应用程序时,这一行显示警告:它崩溃了。很抱歉,我从未编译过该代码。“分配”-有拼写错误-我只是想告诉你一个想法-不是真的编写代码来100%解决你的问题
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell=[[ViewProfileRightPanelCell alloc]init];
     static NSString *cellidentifier=@"ViewProfileRightPanelCell";
    cell=(ViewProfileRightPanelCell*)[tableView dequeueReusableCellWithIdentifier:cellidentifier];
    for (cell in [ViewProfileRightPanelTableView subviews])
    {
        if ([cell isKindOfClass:[ViewProfileRightPanelCell class]])
        {
            if (cell.tag == indexPath.row)
            {
                cell.selected = !cell.selected;
            }
            else
            {
                cell.selected = NO;
            }
        }
    }
}
- (void) setSelected:(BOOL) selected
{
     _selected = selected;
     if(selected)
    {
         self.rightpanelLabel1.text = self.selectedText;
    }
    else
    {
         self.rightpanelLabel1.text = self.deselectedText;
    }
}