只是序言,我是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