我有多个.xib文件和多个视图控制器。
问题是当我从子视图向父视图控制器传递数据时,数据已成功传递。但是当我切换到另一个Subview并回到已经通过丢失的父视图控制器数据时。
我一直在NSMutablearray中传递数据,那么当我切换视图时,我应该如何备份它不会丢失的传递数据?
ForStand Button是NSMutablearray,用于保存来自子视图的传入数据,如下图所示,当我切换到另一个子视图并返回主视图时,它变为null。
以下是示例输出:
2012-03-06 13:44:38.184 Avicii[726:b603] ForStand Button = '(null)'
server did not accept client registration 68
2012-03-06 13:44:41.809 Avicii[726:b603] StandLocations (
"Point Stand",
"Near Stand"
)
2012-03-06 13:44:43.252 Avicii[726:b603] ForStand Button = 'Near Stand'
server did not accept client registration 68
2012-03-06 13:44:56.984 Avicii[726:b603] ForStand Button = '(null)'
server did not accept client registration 68
Subview数据中的传递如下:
- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
StartHuntViewController *startHuntController = [[StartHuntViewController alloc] initWithNibName:@"StartHuntView" bundle:nil];
startHuntController.forStandButton = [stands objectAtIndex:indexPath.row];
startHuntController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:startHuntController animated:YES];;
// startHuntController.standLocation.text=[stands objectAtIndex:indexPath.row];
[startHuntController release];
startHuntController =nil;
}
在父级中,ForStand初始化为
in .h
@property (nonatomic, retain)NSMutableArray *forStandButton;
in .m
@synthesize forStandButton;
答案 0 :(得分:0)
在内存消耗的情况下,您的父视图控制器数据变量可能会被释放...
我建议在Appdelegate
中创建变量并使用
[UIApplication shared application] delegate]
或仅创建一个新的单例类来存储此数据..