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];
}