Domanda

Il problema è questo ...

Ho creato una classe che estende UIBezierClass chiamato PathExtended, in cui ho aggiunto NSString ID;

Ho, poi, una serie di PathExtended. Nel metodo drawRect ho scritto:

p = [[PathExtended alloc] init];

for (int i=0; i<[arrayOfPaths count]; i++) {

    [p appendPath:[arrayOfPaths objectAtIndex:i]];
    [p closePath];
}

[p applyTransform:CGAffineTransformMake(a, b, c, d, e, f)];
[p fill];

Ora, se prova che ho nel metodo touchend:

if ([p containsPoint:pointTouched]) {
            NSLog(@"There is!");
        }

E 'ok !!! Invece, se la prova i:

if ([p containsPoint:pointTouched]) {
            NSLog(@"ID= %@", p.ID);
        }

Log è vuoto !!

posso capire perché succede, ma, non riesco a capire come risolvere il problema. Ho pensato che appendPath crea un percorso unico, quindi, ogni singolo informazioni sul percorso, come ID, è perduto. Ho pensato anche che, se disegno ogni percorso senza utilizzare il metodo appendPath posso risolvere il problema, ma ... non so ... sembra come se sto seguendo la strada sbagliata.

Qualche idea ??? Ci scusiamo per il mio inglese (io sono italiano: P)

EDIT:

PathExtended .h

@interface PathExtended : UIBezierPath {

NSString* ID;
}

@property (nonatomic, readwrite) NSString* ID;

-(id) initwithID:(NSString*) _ID;
È stato utile?

Soluzione

Imagine what would happen if you created a subclass of NSDecimalNumber, call it MyImaginaryNumber, such that your subclass stored an imaginary component. What would happen if you tried to call a method like -decimalNumberByAdding:? You wouldn't really expect NSDecimalNumber's implementation of that method to include your imaginary part in the resulting number, would you? NSDecimalNumber obviously doesn't know anything about the imaginary part, so it can't be expected to do the right thing.

If you want -appendPath: to work with your PathExtended objects, you'll need to override -appendPath: with an implementation that preserves the extra information in PathExtended. You can still call UIBezierPath's implementation from inside your own if that's useful, of course. For example, if your ID's are composable, you might do something like:

-(PathExtended*)appendPath:(PathExtended*)path
{
    PathID newID = [self composeID:path.ID];
    PathExtended *newPath = [PathExtended pathWithBezierPath:[super appendPath:path] ID:newID];
    return newPath;
}

I'm not sure why your log message didn't print at all, if that's what happened, but it's likely due to UIBezierPath not having an ID property.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top