我遇到了 prepareforsegue 风格的问题。我是,正如你所说的那样,我的问题对 Xcode 来说很新,我只是没弄对:
我有一个 LAFirstView 从解析中读取数据,我保存在一个名为“kundUppgifter”的数组中。
现在我需要将文本从 objectatindex:index 发送到下一个被调用的 View LASecondView。 在 LASecondView 中,我声明了一个名为 myLabel 的标签,我希望在其中显示文本。
我一直在 Stackoverflow 上阅读相关内容,但问题是当我阅读其他答案时,我不明白用什么来代替。我在 LAFirstView 中的代码:看起来像这样,当然它不起作用,但我确实从 NSLog 中得到了正确的东西。 希望得到帮助:
//IMPLEMENT THIS ONE (WHEN DISCLOSURE BUTTON IS PRESSED):
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
[self performSegueWithIdentifier: @"openingHours" sender: self];
NSUInteger index = [mapView.annotations indexOfObject:view.annotation];
PFObject *tempObject = [kundUppgifter objectAtIndex:index];
NSLog(@"%lu", (unsigned long)index);
NSLog(@"%@", [tempObject objectForKey:@"CNAME"]);
}
最佳答案
所以你的问题是它没有将字符串从 LAFirstView 传递到 LASecondView,但日志是正确的?如果是这种情况,您可以在 LAFirstView 上声明一个字符串属性:
@property (strong, nonatomic) NSString* stringToPass;
然后点击披露按钮:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
NSUInteger index = [mapView.annotations indexOfObject:view.annotation];
PFObject *tempObject = [kundUppgifter objectAtIndex:index];
NSLog(@"%lu", (unsigned long)index);
NSLog(@"%@", [tempObject objectForKey:@"CNAME"]);
self.stringToPass = [tempObject objectForKey:@"CNAME"];
[self performSegueWithIdentifier: @"openingHours" sender: self];
}
和prepareForSegue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"openingHours"]) {
LASecondView *secondView = (LASecondView *)segue.destinationViewController;
secondView.labelToUpdate.text = self.stringToPass;
}
}
关于ios - 为 segue 做准备 - 只是不要做对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26091349/