在导航类型应用程序中将数组传递给父视图控制器
我需要将一个数组传递给我的父视图控制器,但我不知道该怎么做。使用委托是我唯一的选择吗?我的应用程序在以下行崩溃:
[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的答案就在你的问题中:)。
当使用 UINavigationController 层次结构时,父视图控制器是 UINavigationController,而不是之前的视图控制器。
如果您想获取该视图控制器,请通过调用
[self.parentViewController viewControllers]
向 UINavigationController 询问其视图控制器列表,然后您可以使用isKindOfClass:< /code> 来确定哪一个是你的。
在这种情况下, NSNotification 也可以工作,或者按照您的建议,委托。
Your answer is in your question :).
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 usingisKindOfClass:
to determine which one is yours.An
NSNotification
could also work in this case, or as you suggest, a delegate.