Hola, a ver si me podeis echar una mano.
Tengo un NSTableView donde puedo añadir direcciones y modificarlas, los objetos que meto en la tabla son del tipo Address, todo funciona bien, pero yo quiero que estas aparezcan en hexadecimal.
Mediante codigo (no se como hacerlo desde el IB) hago esto para asignarle el AddressFormatter a la tabla, con esto me aparecen la direcciones en hexadecimal.
El problema es que cuando edito una direccion y le doy al Enter me aparecen estos mensajes de error.Código:- (void)setFormatter{ NSTableColumn *col = [mTableViewtableColumnWithIdentifier:@"address"]; AddressFormatter *fmt = [[AddressFormatteralloc] init]; [[col dataCell] setFormatter:fmt]; }
¿Que estoy haciendo mal?2013-06-03 10:35:29.323 Disassembler68k[371:903] -[Address copyWithZone:]: unrecognized selector sent to instance 0x100558670
2013-06-03 10:35:29.335 Disassembler68k[371:903] Exception detected while handling key input.
2013-06-03 10:35:29.339 Disassembler68k[371:903] -[Address copyWithZone:]: unrecognized selector sent to instance 0x100558670
Clase Address y AddressFormatter
Cabecera:
Implementacion:Código:@interface Address : NSObject{ @private int address; } - (id)initWithAddress:(int)a; @property int address; @end @interface AddressFormatter : NSFormatter - (NSString *)stringForObjectValue:(id)obj; - (BOOL)getObjectValue:(id *)obj forString:(NSString *)string errorDescription:(NSString **)error; @end
Código:#import "Address.h" @implementation Address //@synthesize address; -(id)init { self = [superinit]; if (self) address = 0; returnself; } -(id)initWithAddress:(int)a { [self init]; address = a; returnself; } -(void)dealloc { [superdealloc]; } @end @implementation AddressFormatter - (NSString *)stringForObjectValue:(id)obj { NSException *error; NSString *strValue; // parameter check if ( obj != nil ) { // identify the type of object to be formatted if ([obj isKindOfClass:[NSNumberclass]]) { // convert the data to a string strValue = [NSString stringWithFormat:@"%x", [obj intValue]]; } else { // raise an exception error = [NSExceptionexceptionWithName:NSInvalidArgumentException reason:@"Unsupported datatype" userInfo:nil]; [error raise]; } } else { // raise an exception error = [NSExceptionexceptionWithName:NSInvalidArgumentException reason:@"Nil argument" userInfo:nil]; [error raise]; } // return the formatting results return strValue; } - (BOOL)getObjectValue:(id *)obj forString:(NSString *)string errorDescription:(NSString **)error { BOOL ok = NO; // parameter check if ( string != nil ) { unsignedint val; NSScanner *scanner = [[NSScanner alloc] initWithString:string]; if ( [scanner scanHexInt: &val] ) { *obj = [[Address alloc] initWithAddress: val]; // ------- creo que esto esta mal ok = (*obj != nil); } } return ok; } @end


Citar

Marcadores