Tag on UItextField received EXC_BAD_ACCESS
HI, Im creating a UItextField trying to get the tag when editing did end. i'm receiving EXC_BAD_ACCESS when the showTag is called :
UITextField *text = [[[UITextField alloc] initWithFrame:CGRectMake(195.0, (m*30)+1 , 70.0, 23.0)] autorelease];
text.keyboardType = UIKeyboardTypeDecimalPad;
text.tag=Myin开发者_JS百科tValue;
[text addTarget:self action:@selector(showTag:) forControlEvents:UIControlEventEditingDidEnd];
[scrollView addSubview:text];
- (IBAction)showTag:(UITextField* )sender{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%@", =[sender tag] ] message:@”" delegate:self cancelButtonTitle:@"Back" otherButtonTitles:nil];
[alert show];
[alert release];
}
Thank You
you are trying
[NSString stringWithFormat:@"%@",[sender tag] ]tag is int value so
[NSString stringWithFormat:@"%@d",[sender tag] ]...i tried this...got no problem...worked for me...
You need to use
[NSString stringWithFormat:@"%i", [sender tag]]
the tag is an int. If you use %@, it is interpreted as a pointer and trying to access that memory address (5 or 22 or whatever the int value of the tag is) fails because it's not valid, hence the crash.
精彩评论