Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.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上的initwithCoder和EncodWithCoder_Ios_Initwithcoder - Fatal编程技术网

iOS上的initwithCoder和EncodWithCoder

iOS上的initwithCoder和EncodWithCoder,ios,initwithcoder,Ios,Initwithcoder,我已尝试使用encodeWithCoder: - (void)encodeWithCoder:(NSCoder *)encoder { [coder encodeObject:self.button1 forKey:@"button1"]; } 我的initWithCoder:如下所示: -(void) initWithCoder:(NSCoder*)decoder { self.button1 = [coder decodeObjectForKey:@"button1"]; }

我已尝试使用
encodeWithCoder:

- (void)encodeWithCoder:(NSCoder *)encoder
{  
  [coder encodeObject:self.button1 forKey:@"button1"];
}
我的
initWithCoder:
如下所示:

-(void) initWithCoder:(NSCoder*)decoder
{
  self.button1 = [coder decodeObjectForKey:@"button1"];
}

使用
按钮1
我保存颜色、方向、角度等的状态,我可以使用
initwithCoder还原它但当我点击按钮时,它没有响应。外观已恢复,但不再调用
iAction

如果手动创建/恢复按钮,则会取消InterfaceBuilder/NIB加载为您提供的自动设置

您需要显式地将目标操作添加到按钮。示例代码中还存在一些语法错误

-(void) initWithCoder:(NSCoder*)decoder
{
  self.button1 = [coder decodeObjectForKey:@"button1"];
  [self.button1 addTarget:self action:@selector(yourIBActionMethod:) forControlEvents:UIControlEventTouchUpInside];
}