将数据传递到两个 viewController 之间的 NSMutablearrays,IOS 4.3

发布于 2025-01-04 15:53:57 字数 1172 浏览 3 评论 0原文

我正在尝试将 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;

我应该做什么?我想代码没有什么问题?

I am trying to pass an object in NSMutablearray to another view's NSmutableArray

I have been looking related question but couldnt figure out whats wrong.

my view switches correctly but it doesnt pass the object in my NSmutable array

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

view i am trying to pass data is

.h file
@interface StartHuntViewController : UIViewController<UIApplicationDelegate,CLLocationManagerDelegate,CoreLocationControllerDelegate> {


    NSMutableArray *forStandButton;


}
@property (nonatomic, assign)NSMutableArray *forStandButton;
.m file

@synthesize forStandButton;

what should i do ? i guess there is nothing wrong with code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只等公子 2025-01-11 15:53:57

这里有很多问题,首先看一下:

@property (nonatomic, assign)NSMutableArray *forStandButton;

为什么财产不保留?

there are many issues here, for first look :

@property (nonatomic, assign)NSMutableArray *forStandButton;

why property is not retain?

画骨成沙 2025-01-11 15:53:57

将分配更改为保留,移动行 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;


}

changed assign to retain, move the line 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;


}
未蓝澄海的烟 2025-01-11 15:53:57

您需要在属性声明中使用retain。由于 forStandButton 是第二个视图的属性,因此您需要确保它已被设置。如果您为其创建一个 setter (setForStandButton),则可以在 setter 方法中放置一个断点。一旦您确认 setter 被调用,请确保它被保留足够长的时间以使其有用。

You need to use retain in the property statement. Since forStandButton is a property of the second view, you want to make sure it is getting set. If you create a setter (setForStandButton) for it, you can put a break point in the setter method. Once you have confirmed that the setter is being called, make sure it is being retained long enough to be useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文