我有两个文件,我试图在它们之间传递一些信息。基本上我有一个布尔属性,我用它来决定我应该使用方法的哪一部分。我创建了一个实例方法,该方法返回此布尔属性以供查看。在我的第一个控制器中,我创建属性并设置它并创建方法,在我的第二个控制器中,我创建该类的一个实例并调用该方法以查看 BOOL 的值。问题是当我调用它时我没有得到正确的答案,我总是得到0。有人可以解释为什么吗?谢谢。在第二个文件中,我有一个使用注释的 mapView,因此在单击地图上的图钉时会调用 title 属性
第一个文件:TableViewController
#import "MyTableViewController.h"
#import "FlickrFetcher.h"
#import "myTableViewControllerPhotoLocation.h"
#import "FlickrImageViewController.h"
#import "FlickrPhotoSort.h"
#import "MapViewController.h"
#import "FlickrPhotoAnnotation.h"
@interface MyTableViewController () <MapViewControllerDelegate>
//This is declared in header
@property bool photoStage;
@end
@implementation MyTableViewController
@synthesize photoStage= _photoStage;
-(BOOL) currentPhotoStage{
NSLog(@"PhotoStage = %@", self.photoStage);
return self.photoStage;
}
-(void) setphotoStage: (bool) photoStage{
if(!_photoStage) _photoStage = NO;
else {
_photoStage = photoStage;
}
}
-(NSArray*) mapAnnotations{
NSMutableArray *annotations= [NSMutableArray arrayWithCapacity:[self.photoArray count]];
for(NSDictionary *photo in self.photoArray)
{
[annotations addObject:[FlickrPhotoAnnotation annotationForPhoto:photo]];
}
//I set the value of self.photoStage here
self.photoStage = YES;
//Prints out 1
NSLog(@"%d", self.photoStage);
return annotations;
}
第二个文件名为 PhotoAnnotation
#import "FlickrPhotoAnnotation.h"
#import "FlickrFetcher.h"
#import "MapKit/Mapkit.h"
#import "MapViewController.h"
#import "MyTableViewController.h"
@interface FlickrPhotoAnnotation ()
@property (nonatomic,strong) MyTableViewController* mapCheck;
@end
@implementation FlickrPhotoAnnotation
@synthesize photo=_photo; //This is a dictionary
@synthesize mapCheck = _mapCheck;
这里出现问题
-(NSString*) title{ //gets called on click of annotation in map
// ALWAYS RETURNS 0 hence if statement fails
NSLog(@"photoStage = %d", [self.mapCheck currentPhotoStage]);
if([self.mapCheck currentPhotoStage])
{
NSLog(@"title = %@", [self.photo objectForKey:FLICKR_PHOTO_TITLE]);
NSString *title = [self.photo objectForKey:FLICKR_PHOTO_TITLE];
if([title isEqualToString:@""]) title = @"No Title";
NSLog(@"title = %@", title);
return title;
}else {
NSString * cellTitle = [self.photo objectForKey:@"_content"];
NSRange cellRange = [cellTitle rangeOfString:@","];
NSString * cellMainTitle = [cellTitle substringToIndex:cellRange.location];
return cellMainTitle;
//[self.photo objectForKey:FLICKR_PHOTO_TITLE];
}
}