Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios int、bool、nsstring、idexpath的属性_Ios_Objective C_Properties - Fatal编程技术网

Ios int、bool、nsstring、idexpath的属性

Ios int、bool、nsstring、idexpath的属性,ios,objective-c,properties,Ios,Objective C,Properties,我在.h类中声明了int的属性,如: @property (nonatomic) int selectedIndex; 问题是当我切换到另一个类并返回到我的tableview时,selectedIndex的值丢失。我想将所选值保存在selectedIndex中吗 帮我,伙计,我在财产申报上犯了什么错误 在didSelect函数中,输入并存储值: -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSInde

我在.h类中声明了
int
的属性,如:

@property (nonatomic) int  selectedIndex;
问题是当我切换到另一个类并返回到我的tableview时,
selectedIndex
的值丢失。我想将所选值保存在
selectedIndex
中吗

帮我,伙计,我在财产申报上犯了什么错误

在didSelect函数中,输入并存储值:

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

     selectedIndex = (int)indexPath.row;
     [tableView reloadData];
     myTimeSlot=[timeSlot objectAtIndex:indexPath.row];


}  
在CellforRowatinexpth中,我正在检索它,比如:

if(indexPath.row == selectedIndex)
{
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
    cell.accessoryType = UITableViewCellAccessoryNone;
}

在同一个类中一切都很好,但当我导航到另一个类时,我的值丢失了…?

您的属性声明本身没有问题。你需要向人们展示更多的代码来帮助你。然而,一个明显的猜测是,您正在类的一个实例上设置属性,然后无意中从另一个实例读取该属性,从而得到意外的结果。属性声明中没有错误。您需要显示存储到属性和读取属性的代码。另外,您确定在这两种情况下使用的对象相同(并且您的引用不是
nil
)?您没有使用访问器,而是直接设置变量。声明变量也可能会出错。@gnasher729您能解释一下吗??我已经将它合成为主动getter setter。编写
NSLog(@“Object is%@”,self)并显示打印的值/地址。