我試圖從一個視圖控制器到另一個傳遞一個對象(PFObject)通行證數據
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
RestauCardViewController *restauCard = [[RestauCardViewController alloc]init];
RestaurantAnnotation *restoAnnotation = (RestaurantAnnotation *)view.annotation;
restauCard.restaurant = restoAnnotation.restaurant;
[self performSegueWithIdentifier:@"segueToCard" sender:nil];
}
當我嘗試顯示在其他視圖控制器我得到空的對象:
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
@interface RestauCardViewController : UIViewController
@property(nonatomic) PFObject *restaurant;
@end
這是我的viewDidLoad功能
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"The restaurant name is : %@",_restaurant[@"nom"]);
}
請參閱http://stackoverflow.com/questions/14805954/mkannotationview-push-to-view-controller-when-detaildesclosure-button-is-clicked。不要使用屬性或ivar來存儲選擇,而應將註釋'view'作爲'sender'傳遞。它使代碼更加獨立,並使用api已經提供的功能。 – Anna