2012-01-15 184 views
3

我正在開發應用程序以虛擬化Twitter趨勢。我獲取地點的位置併爲它們中的每一個創建註釋。不幸的是,當我點擊註釋時,應用程序崩潰,並在main.m文件上發出sigabrt錯誤。在我第一次運行它的工作,但之後,每次我得到的錯誤。我不知道我改變了什麼。當MapKit註釋點擊時,應用程序崩潰

2012-01-15 12:34:29.786 twittertrends[1248:ef03] -[NSCFNumber stringByStandardizingWhitespace]: unrecognized selector sent to instance 0x5854b10 
    2012-01-15 12:34:29.790 twittertrends[1248:ef03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFNumber stringByStandardizingWhitespace]: unrecognized selector sent to instance 0x5854b10' 
    *** Call stack at first throw: 
    (
     0 CoreFoundation      0x012725a9 __exceptionPreprocess + 185 
     1 libobjc.A.dylib      0x013c6313 objc_exception_throw + 44 
     2 CoreFoundation      0x012740bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
     3 CoreFoundation      0x011e3966 ___forwarding___ + 966 
     4 CoreFoundation      0x011e3522 _CF_forwarding_prep_0 + 50 
     5 UIKit        0x005f4340 -[UICalloutView setSubtitle:animated:] + 88 
     6 UIKit        0x005f4010 -[UICalloutView setSubtitle:] + 49 
     7 MapKit        0x003630ac -[MKAnnotationContainerView _showBubbleForAnnotationView:bounce:scrollToFit:userInitiated:avoid:] + 537 
     8 MapKit        0x003643ed -[MKAnnotationContainerView _setSelectedAnnotationView:bounce:pressed:scrollToFit:userInitiated:avoid:] + 653 
     9 MapKit        0x0035d4bc -[MKAnnotationContainerView _setSelectedAnnotationView:bounce:pressed:scrollToFit:userInitiated:] + 144 
     10 MapKit        0x00334ab3 -[MKMapView handleTap:] + 459 
     11 UIKit        0x007554f2 -[UIGestureRecognizer _updateGestureWithEvent:] + 730 
     12 UIKit        0x007514fe -[UIGestureRecognizer _delayedUpdateGesture] + 47 
     13 UIKit        0x00757afc _UIGestureRecognizerUpdateObserver + 584 
     14 CoreFoundation      0x0125389b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27 
     15 CoreFoundation      0x011e86e7 __CFRunLoopDoObservers + 295 
     16 CoreFoundation      0x011b11d7 __CFRunLoopRun + 1575 
     17 CoreFoundation      0x011b0840 CFRunLoopRunSpecific + 208 
     18 CoreFoundation      0x011b0761 CFRunLoopRunInMode + 97 
     19 GraphicsServices     0x01e501c4 GSEventRunModal + 217 
     20 GraphicsServices     0x01e50289 GSEventRun + 115 
     21 UIKit        0x004d2c93 UIApplicationMain + 1160 
     22 twittertrends      0x00002669 main + 121 
     23 twittertrends      0x000025e5 start + 53 
    ) 





#import <Foundation/Foundation.h> 
#import "Mapkit/Mapkit.h" 


@interface AvailablePlaces : NSObject <MKAnnotation>{ 

    NSString *_name; 
    NSString *_address; 
    CLLocationCoordinate2D _coordinate; 

} 

@property (copy) NSString *name; 
@property (copy) NSString *address; 
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate; 

- (id)initWithName:(NSString*)name address:(NSString*)address coordinate:(CLLocationCoordinate2D)coordinate; 

@end 

#import "AvailablePlaces.h" 


@implementation AvailablePlaces 
@synthesize name = _name; 
@synthesize address = _address; 
@synthesize coordinate = _coordinate; 

- (id)initWithName:(NSString*)name address:(NSString*)address coordinate:(CLLocationCoordinate2D)coordinate { 
    if ((self = [super init])) { 
     self.name = [name copy]; 
     self.address = [address copy]; 
     _coordinate = coordinate; 
    } 
    return self; 
} 

- (NSString *)title { 
    return _name; 
} 

- (NSString *)subtitle { 
    return _address; 
} 

- (void)dealloc 
{ 
    [_name release]; 
    _name = nil; 
    [_address release]; 
    _address = nil;  
    [super dealloc]; 
} 

@end 

--- viewcontroller.m -----

CLLocationCoordinate2D coordinate; 
     coordinate.latitude = latitude.doubleValue; 
     coordinate.longitude = longitude.doubleValue;    
     AvailablePlaces *annotation = [[[AvailablePlaces alloc] initWithName:name address:woeid coordinate:coordinate] autorelease]; 
     [_mapView addAnnotation:annotation]; 

----- ----------的main.m

#import <UIKit/UIKit.h> 

int main(int argc, char *argv[]) 
{ 
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    int retVal = UIApplicationMain(argc, argv, nil, nil); 
    [pool release]; 
    return retVal; 
} 
+4

「我不知道我改變了什麼。」使用版本控制。 – 2012-01-15 10:35:20

+0

應該有一個錯誤消息,最有可能和異常(我想這是關於一個無法識別的選擇器)。請張貼。 – DarkDust 2012-01-15 10:37:00

+0

我在字符串stringByStandardizingWhitespace的xcode中添加了錯誤信息 – uyqusuz 2012-01-15 10:38:39

回答

2

最有可能在您的通話傳遞的NSNumber實例作爲nameinitWithName:address:coordinate:。所以你需要注意,你的name變量包含NSString

+0

我不明白你的意思「很可能你傳遞了一個NSNumber的實例作爲名字」。名稱被定義爲nsstring,我可以在地圖視圖上添加註釋,但是當我點擊註解時會得到錯誤。你能更具體地說明我應該在代碼上做些什麼改變。 – uyqusuz 2012-01-15 12:52:42

+0

你有*定義它是一個NSString,但它似乎崩潰是因爲你確實通過了一個NSNumber。你可以通過向' - (id)initWithName:(NSString *)名稱地址:(NSString *)地址座標:(CLLocationCoordinate2D)座標:'NSLog(@「Name is \」%@ \ 「(class%@)」,name,[name class]);' – DarkDust 2012-01-15 13:03:29

+0

class是NSCFString – uyqusuz 2012-01-15 13:14:56

相關問題