我遇到了prepareforsegue-style的问题。我是,你可以告诉我对Xcode很新的问题,我只是没有做到这一点:
我有一个LAFirstView从解析中读取数据,我将其保存在名为' kundUppgifter'。
的数组中。现在我需要将objectatindex:index中的文本发送到下一个被调用的视图 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"]);
}
答案 0 :(得分:1)
所以你的问题是它没有将字符串从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;
}
}