在导航类型应用程序中将数组传递给父视图控制器

发布于 2024-11-10 12:54:46 字数 1495 浏览 0 评论 0原文

我需要将一个数组传递给我的父视图控制器,但我不知道该怎么做。使用委托是我唯一的选择吗?我的应用程序在以下行崩溃:

[self.parentViewController setrecipientItems:remoteRecipientItems];

并显示消息:

[UINavigationController setrecipientItems:]:无法识别的选择器发送到实例 0x8a10ab0

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {



    int newRow = [indexPath row];
    int oldRow = (lastIndexPath !=nil)?[lastIndexPath row]:-1;

    if (newRow != oldRow) {
        UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
        newCell.accessoryType = UITableViewCellAccessoryCheckmark;

        UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];

        oldCell.accessoryType = UITableViewCellAccessoryNone;

        //  lastIndexPath = indexPath;
        lastIndexPath = [indexPath retain];


    }

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    // UIViewController may not respond to setrecipientItems: warning
    [self.parentViewController setrecipientItems:remoteRecipientItems]; 

    [[self.parentViewController.] ]


    [self.navigationController popViewControllerAnimated:YES];


}

另外,我的父 UIViewController 的设置如下:

#import <UIKit/UIKit.h>


@interface AddRecipientsTableViewController : UITableViewController {
NSMutableArray *recipientItems;
}
@property(nonatomic,retain)NSMutableArray *recipientItems;



@end

I need to pass an array to my parent view controller, and I'm not sure how to do that. Is my only choice to use a delegate? My application crashes at the line:

[self.parentViewController setrecipientItems:remoteRecipientItems];

with the message:

[UINavigationController setrecipientItems:]: unrecognized selector sent to instance 0x8a10ab0

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {



    int newRow = [indexPath row];
    int oldRow = (lastIndexPath !=nil)?[lastIndexPath row]:-1;

    if (newRow != oldRow) {
        UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
        newCell.accessoryType = UITableViewCellAccessoryCheckmark;

        UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];

        oldCell.accessoryType = UITableViewCellAccessoryNone;

        //  lastIndexPath = indexPath;
        lastIndexPath = [indexPath retain];


    }

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    // UIViewController may not respond to setrecipientItems: warning
    [self.parentViewController setrecipientItems:remoteRecipientItems]; 

    [[self.parentViewController.] ]


    [self.navigationController popViewControllerAnimated:YES];


}

Also my parent UIViewController is set up like this:

#import <UIKit/UIKit.h>


@interface AddRecipientsTableViewController : UITableViewController {
NSMutableArray *recipientItems;
}
@property(nonatomic,retain)NSMutableArray *recipientItems;



@end

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

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

发布评论

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

评论(1

千纸鹤 2024-11-17 12:54:46

你的答案就在你的问题中:)。

[UINavigationController setrecipientItems:]: unrecognized selector sent to instance 0x8a10ab0

当使用 UINavigationController 层次结构时,父视图控制器是 UINavigationController,而不是之前的视图控制器。

如果您想获取该视图控制器,请通过调用 [self.parentViewController viewControllers] 向 UINavigationController 询问其视图控制器列表,然后您可以使用 isKindOfClass:< /code> 来确定哪一个是你的。

在这种情况下, NSNotification 也可以工作,或者按照您的建议,委托。

Your answer is in your question :).

[UINavigationController setrecipientItems:]: unrecognized selector sent to instance 0x8a10ab0

The parent view controller, when using a UINavigationController hierarchy, is UINavigationController, not your previous view controller.

If you want to get at that view controller, ask the UINavigationController for its list of view controllers by calling [self.parentViewController viewControllers], and then you can cycle through that NSArray using isKindOfClass: to determine which one is yours.

An NSNotification could also work in this case, or as you suggest, a delegate.

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