gpt4 book ai didi

objective-c - 将数组传递给导航类型应用程序中的父 View Controller

转载 作者:行者123 更新时间:2023-11-29 13:48:26 27 4
gpt4 key购买 nike

我需要将一个数组传递给我的父 View Controller ,但我不确定该怎么做。使用委托(delegate)是我唯一的选择吗?我的应用程序在以下行崩溃:

[self.parentViewController setrecipientItems:remoteRecipientItems];

消息:

[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];


}

我的父 UIViewController 也是这样设置的:

#import <UIKit/UIKit.h>


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



@end

最佳答案

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

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

当使用 UINavigationController 层次结构时,父 View Controller 是 UINavigationController,而不是您以前的 View Controller 。

如果你想访问那个 View Controller ,通过调用 [self.parentViewController viewControllers] 向 UINavigationController 询问它的 View Controller 列表,然后你可以使用 循环访问那个 NSArray isKindOfClass: 判断哪一个是你的。

在这种情况下,NSNotification 也可以工作,或者如您所建议的,委托(delegate)。

关于objective-c - 将数组传递给导航类型应用程序中的父 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6171432/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com