【发布时间】:2016-03-10 12:02:15
【问题描述】:
所以,我正在阅读 this related SO,因为它最终也是我想做的事情。
我在我的destinationViewController 的头文件中添加了一个属性:
@property (nonatomic, strong) NSString *incomingSegue;
我已经在destinationViewController的实现文件中合成了它:
@synthesize incomingSegue = _incomingSegue;
我已将以下几行添加到我的 prepareForSegue 方法中,用于 sourceViewController(取决于触发 segue 的):
[segue.destinationViewController setIncomingSegue:@"edit"];
[segue.destinationViewController setIncomingSegue:@"add"];
最后,我有一个过程来检查我的destinationViewController 的实现文件中设置了哪个值:
if (_incomingSegue == @"add")
{
//snipped code here
}
else if (_incomingSegue == @"edit")
{
//snipped code here
}
所以,显然我错过了一些东西。当我尝试执行 segue 时,我得到一个错误,在 SO 中出现了大约 1000 次,这使得很难弄清楚我忽略了哪些细节。这件事在我的 sourceViewController 上的 prepareForSegue 方法中触发(根据断点):
无法识别的选择器发送到实例
我可以不使用文字字符串 (@"string") 代替 (NSString *),或者是其他什么东西引发错误?
更新(已解决):
我的 prepareForSegue 方法更详细的描述:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"editSegue"])
{
//snipped
[segue.destinationViewController setIncomingSegue:@"edit"];
}
else if ([[segue identifier] isEqualToString:@"addSegue"])
{
//snipped
DestinationViewController *dtv = (DestinationViewController *)[[segue destinationViewController]topViewController];
[dvc setIncomingSegue:@"add"]
}
}
事实证明,我必须使用我声明的 DestinationViewController 类对象来设置值。而不是像我对 editSegue 所做的那样仅引用 segue.destinationViewController。我没有为 editSegue 声明 DestinationViewController 类对象,因此它按预期工作。
【问题讨论】:
标签: objective-c ios