只是序言,我是iOS开发的新手。我环顾了一会儿,尝试找到答案,无论是在这里还是通过Google。将视图控制器放到导航堆栈中导致SIGABRT
我的应用程序加载到带有注释的mapview中。如果用户点击其中一个注释,会显示带附件按钮的标注视图。我遇到的问题是在点击附件按钮时调用的方法。我想要显示特定注释的细节视图,但是当我点击附件按钮时,应用程序会与SIGABRT崩溃。
// method that provides the view for when the callout accessory button is tapped
- (void)mapView:(MKMapView *)mapView
annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
// grabs the annotation's title from the annotation view
NSString *viewTitle = view.annotation.title;
// grabs corresponding POI object for map annotation
PointOfInterest *object = [[PointOfInterest alloc] init];
object = [dictionary objectForKey:(NSString *)viewTitle];
// assigns title and subtitle ivars to variables to be passed into detailviewcontroller init
NSString *title = object._title;
NSString *subtitle = object._subtitle;
UIImage *picture = object._picture;
NSString *description = object._description;
// releases POI object after all the information has been taken from it
[object release];
// inits detailVC
DetailVC *detailVC = [[DetailVC alloc] initWithNibName:@"DetailVC"
bundle:[NSBundle mainBundle]];
// sets the nsstring ivars in the DVC which correspond to the POI information
detailVC.thetitleText = title;
detailVC.thesubtitleText = subtitle;
detailVC.thepictureImage = picture;
detailVC.thedescriptionText = description;
// sets the "back" button on the navigation controller to say "Back to Map"
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:@"Back to Map"
style:UIBarButtonItemStyleBordered
target:nil
action: nil];
[[self navigationItem] setBackBarButtonItem: newBackButton];
[newBackButton release];
// pushes navcontroller onto the stack and releases the detail viewcontroller
[self.navigationController pushViewController:detailVC animated:YES];
[detailVC release];
}
我还没有添加图片和描述,因为我只是想让视图显示标题和副标题。
这里是DetailViewController类代码 部首:
@interface DetailViewController : UIViewController {
IBOutlet UIScrollView *scrollview;
IBOutlet UILabel *thetitle;
NSString *thetitleText;
IBOutlet UILabel *thesubtitle;
IBOutlet UIImage *thepicture;
IBOutlet UITextView *thedescription;
}
@property (nonatomic, retain) UIScrollView *scrollview;
@property (nonatomic, retain) UILabel *thetitle;
@property (nonatomic, retain) NSString *thetitleText;
@property (nonatomic, retain) UILabel *thesubtitle;
@property (nonatomic, retain) UIImage *thepicture;
@property (nonatomic, retain) UITextView *thedescription;
// method that creates the custom detail view with the corresponding information from
// the point of interest objects
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil title:(NSString*)title subtitle:(NSString *)subtitle picture:(UIImage *)picture description:(NSString *)description;
@end
实现:
@implementation DetailViewController
@synthesize scrollview, thetitle, thesubtitle, thepicture, thedescription, thetitleText;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil title:(NSString *)title subtitle:(NSString *)subtitle picture:(UIImage *)picture description:(NSString *)description;
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSLog(@"view initialized");
}
return self;
}
- (void)dealloc
{
[scrollview release];
[thetitle release];
[thesubtitle release];
[thepicture release];
[thedescription release];
[thetitleText release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"view did load");
[thetitle setText:self.thetitleText];
NSLog(@"thetitle text set");
// Do any additional setup after loading the view from its nib.
// [thetitle setText:title];
// NSLog(@"set title");
// [thesubtitle setText:subtitle];
// NSLog(@"set subtitle");
// thepicture = picture;
// [thedescription setText:description];
// NSLog(@"set description");
}
这里是SIGABRT输出:
2011-07-12 19: 05:06.678 mkeBOAT [1687:ef03]标注配件Tap
2011-07-12 19:05:06.679 mkeBOAT [1687:ef03]美国银行大厦
2011-07-12 19:05:06.680 mkeBOAT [1687:ef03](空)
2011-07-12 19:05:06.680 mkeBOAT [1687:ef03](空),(空)
2011-07-12 19:05:06.680 mkeBOAT [1687:ef03]视图初始化
2011 -07-12 19:05:06.711 mkeBOAT [1687:ef03] *由于未捕获异常而终止应用
'NSUnknownKeyException',原因:'[setValue:forUndefinedKey:]:该类不是密钥描述符合密钥值的密钥值。
我不认为字典工作正常,因为它为应该实际上有东西的值输出null。
感谢您的帮助!
你解决了这个布拉德利?看看我的回答 – 2011-07-13 20:26:00
你的错误的描述似乎暗示字典不是用键种子,或者你的对象不能处理它给出的键值。你可以检查POI对象是否可以处理你给的东西? – spamboy