swapd0
03/06/2013, 11:40
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.
- (void)setFormatter{
NSTableColumn *col = [mTableViewtableColumnWithIdentifier:@"address"];
AddressFormatter *fmt = [[AddressFormatteralloc] init];
[[col dataCell] setFormatter:fmt];
}
El problema es que cuando edito una direccion y le doy al Enter me aparecen estos mensajes de error.
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
¿Que estoy haciendo mal?
Clase Address y AddressFormatter
Cabecera:
@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
Implementacion:
#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:NSInvalidArgumentExce ption
reason:@"Unsupported datatype"
userInfo:nil];
[error raise];
}
}
else
{
// raise an exception
error = [NSExceptionexceptionWithName:NSInvalidArgumentExce ption
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
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.
- (void)setFormatter{
NSTableColumn *col = [mTableViewtableColumnWithIdentifier:@"address"];
AddressFormatter *fmt = [[AddressFormatteralloc] init];
[[col dataCell] setFormatter:fmt];
}
El problema es que cuando edito una direccion y le doy al Enter me aparecen estos mensajes de error.
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
¿Que estoy haciendo mal?
Clase Address y AddressFormatter
Cabecera:
@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
Implementacion:
#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:NSInvalidArgumentExce ption
reason:@"Unsupported datatype"
userInfo:nil];
[error raise];
}
}
else
{
// raise an exception
error = [NSExceptionexceptionWithName:NSInvalidArgumentExce ption
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