0

我几乎关注了这篇文章。视图控制器将通过情节提要推送。这里是相关代码:
ViewController.m:

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    NSLog(@"%@", view.annotation.title);
    MapPoint *annView = view.annotation;
    DetailViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
    dvc.title = @"my own Details";
    dvc.titleTMP = annView.title;
    dvc.subtitleTMP = annView.subtitle;

    [self.navigationController pushViewController:dvc animated:YES];
}

地图点.h:

@interface MapPoint : NSObject <MKAnnotation>
{
    NSString *_title;
    NSString *_subtitle;
    CLLocationCoordinate2D _coordinate;
    UIImage *_storeImage;
}

@property (copy) NSString *title;
@property (copy) NSString *subtitle;
@property (nonatomic, readonly) UIImage *storeImage;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;


- (id)initWithTitle:(NSString*)title subtitle:(NSString*)subtitle coordinate:(CLLocationCoordinate2D)coordinate storeImage:(UIImage*)storeImage;

和 DetailViewController:

@interface DetailViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *branchImage;
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UITextView *textView;

我认为我的错误在于calloutAccessoryControlTapped方法,但我不知道这个问题的真正原因是什么。

4

2 回答 2

1

如果您使用情节提要,可以prepareForSegue像您所做的那样在类中使用方法和设置。

我发布了一部分代码

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

if([segue.identifier isEqualToString:@"Brs"]){
    NSLog(@"segue %@ ",[segue identifier]);
    [segue.destinationViewController setPath:[ris_xml objectAtIndex:index_post-1] ];
    }
}

在此示例中,仅当他的标识符为“Brs”时,我才设置下一个 UIViewController 的属性“Path”。要使用此方法,需要将 UIviewController 标识符设置到情节提要右侧面板中。如果您在情节提要中有它,则无需实例化新的 UIViewController 。

于 2013-04-22T21:16:30.630 回答
0

我通过考虑加载顺序来解决它。
所有要做的就是创建临时的@properties

@interface DetailViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *branchImage;
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UITextView *textView;
@property (nonatomic) NSString *titleTMP;        //added
@property (nonatomic) NSString *subtitleTMP;     //added

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    NSLog(@"%@", view.annotation.title);
    MapPoint *annView = view.annotation;
    DetailViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
    dvc.title = @"my own Details";
    dvc.titleTMP = annView.title;
    dvc.subtitleTMP = annView.subtitle;

    [self.navigationController pushViewController:dvc animated:YES];
}

细节视图控制器:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    titleLabel.text = titleTMP;
    textView.text = subtitleTMP;

}
于 2013-04-22T15:12:06.823 回答