Padin215
Padin215

Reputation: 7484

converting a UITextField tag to a string

this gives me an error, "Bad Reciever type 'NSIntegar" (aka 'int').

    NSString *tempTag = [((UITextField *)[self.dataSetDictionary objectForKey:key]).tag stringValue];

trying to typecast a uitextfield's tag to an string. i can use [NSString stringWithFormat] fine, just can't figure out why this way won't work.

Upvotes: 0

Views: 642

Answers (3)

MadhavanRP
MadhavanRP

Reputation: 2830

tag is a property of UIView object of NSInteger data type. You cannot pass messages to it. stringValue should be called on NSNumber. What you should be doing is

NSString *tempTag=(NSString*)[[NSNumber numberWithInt:[(UITextField*)[self.dataSetDictionary objectForKey:key] tag]] stringValue];

Upvotes: 2

ader
ader

Reputation: 5393

NSIntegers are not objects

more info

Upvotes: -3

Ole Begemann
Ole Begemann

Reputation: 135578

You have to use stringWithFormat:

UITextField *textField = (UITextField *)[self.dataSetDictionary objectForKey:key];
NSString *tempTag = [NSString stringWithFormat:@"%d", textField.tag];

just can't figure out why this way won't work.

Because tag is a scalar integer and not an object. You can't send messages like stringValue to non-objects.

Upvotes: 4

Related Questions