问题描述
- onSaveInstanceState()保存数值
-
需要在onSaveInstanceState()中保存数组列表的值,数值是来自onCreat方法的数组。但是系统运行后报错。public void onSaveInstanceState(Bundle savedInstanceState) { savedInstanceState.putParcelable("Old", (Parcelable) profileDetails ); super.onSaveInstanceState(savedInstanceState); }
在onCreate()
if (savedInstanceState != null) { profileDetails= (ArrayList<ProfileDetails>)savedInstanceState.getParcelable("Old"); } else { profileDetails = GetSearchResults(); }
解决方案
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addAnimation:) name:UIApplicationWillEnterForegroundNotification object:nil];
}
- (void)addAnimation:(NSNotification *)notificaiton
{
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.fromValue = [NSNumber numberWithFloat: 2*M_PI];
animation.toValue = [NSNumber numberWithFloat:0.0f];
animation.duration = 4.0f;
animation.repeatCount = INFINITY;
[imageLeft.layer addAnimation:animation forKey:@"SpinAnimation"];
[imageRight.layer addAnimation:animation forKey:@"SpinAnimation"];
}
解决方案二:
profileDetails 这个东西没有实现Parcelable接口
时间: 2024-09-20 06:27:37