需要在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"];
}