我正在尝试将NSMutablearray中的对象传递给另一个视图的NSmutableArray
我一直在寻找相关的问题,但无法弄清楚什么是错的。
我的视图正确切换但它没有传递我的NSmutable数组中的对象
- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
StartHuntViewController *startHuntController = [[StartHuntViewController alloc] initWithNibName:@"StartHuntView" bundle:nil];
startHuntController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:startHuntController animated:YES];;
startHuntController.forStandButton = [stands objectAtIndex:indexPath.row];// doesnt work
// startHuntController.standLocation.text=[stands objectAtIndex:indexPath.row]; // this works
[startHuntController release];
[self.mytableView reloadData];
}
查看我正在尝试传递数据
.h file
@interface StartHuntViewController : UIViewController<UIApplicationDelegate,CLLocationManagerDelegate,CoreLocationControllerDelegate> {
NSMutableArray *forStandButton;
}
@property (nonatomic, assign)NSMutableArray *forStandButton;
.m file
@synthesize forStandButton;
我该怎么办?我猜代码有什么问题吗?
答案 0 :(得分:2)
这里有很多问题,首先看一下:
@property (nonatomic, assign)NSMutableArray *forStandButton;
为什么不保留财产?
答案 1 :(得分:0)
您需要在property语句中使用retain。由于forStandButton
是第二个视图的属性,因此您需要确保它已设置。如果为它创建一个setter(setForStandButton
),则可以在setter方法中放置一个断点。一旦确认正在调用setter,请确保将其保留足够长的时间以使其有用。
答案 2 :(得分:0)
将分配更改为保留,移动第startHuntController.forStandButton = [stands objectAtIndex:indexPath.row];
行
- (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 release];
startHuntController =nil;
}