ios - 为 segue 做准备 - 只是不要做对

标签 ios mkmapview segue

我遇到了 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/

相关文章:

iphone - 如何为 UIToolbar 上的按钮添加滚动?

ios - MkMapView注解选择困境?

objective-c - 动画删除注释

ios - 如何在MKMapView iOS上以编程方式显示用户位置?

swift - 使用辅助函数从另一个类执行 Segue

ios - iOS 上的 resolveLocalFileSystemURL 每次使用不同的 App UUID

ios - 使用 SDWebImage 加载图像时出现问题

xcode - 模拟器中的黑屏问题

ios - 触发从表格单元格到另一页的 Segue

ios - 将数据从父 View Controller 传递到 subview Controller Swift 4