我正在尝试将视图控制器中的对象传递给另一个。 在destinationController中我有:
@interface destinationController : UITableViewController{
destinationController *object;
@property(nonatomic,copy) destinationController *object;
在viewController中包含我的信息:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
[self performSegueWithIdentifier:@"destinationController" sender:self];
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:@"destinationController"])
{
destinationController *dC =[segue destinationViewController];
NSInteger selected = [[self.tableView indexPathForSelectedRow] row];
dC.object=[vcArray objectAtIndex:selected];
其中vcArray包含数字和名称,但我只想要选定的行。 尝试将所选对象传递给destinationController中的对象似乎不起作用。相反,它给了我错误:
[viewController copyWithZone:]:无法识别的选择器发送到实例0x8000140 2012-11-14 18:08:25.039 app [3314:13d03] *由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [viewController copyWithZone:]:无法识别的选择器发送到实例0x8000140'* 第一次抛出调用堆栈: (0x18e6012 0x12abe7e 0x19714bd 0x18d5bbc 0x18d594e 0x12a8cc9 0x83b2 0x5c22 0x63aac7 0x2d5422 0x5a68 0x2a28d5 0x2a2b3d 0xca9e83 0x18a5376 0x18a4e06 0x188ca82 0x188bf44 0x188be1b 0x1dae7e3 0x1dae668 0x1f365c 0x1f4d 0x1e75) libc ++ abi.dylib:terminate调用抛出异常
我认为问题在于我没有正确分配对象
答案 0 :(得分:1)
问题出在你的财产声明中:
@property(nonatomic,copy) destinationController *object;
这表示无论何时将对象分配给此属性,都会复制该对象。
但是,正如您的错误消息所示 - 您尚未实施NSCopying协议所需的方法(copy
来自哪里)。
您可能应将此声明更改为:
@property(nonatomic, strong) destinationController *object;