Ios4 UItextField上的标记已接收EXC\u错误\u访问
嗨, 我正在创建一个UItextField,试图在编辑结束时获取标记。调用showTag时,我收到EXC\u BAD\u访问权限:Ios4 UItextField上的标记已接收EXC\u错误\u访问,ios4,tags,uitextfield,exc-bad-access,Ios4,Tags,Uitextfield,Exc Bad Access,嗨, 我正在创建一个UItextField,试图在编辑结束时获取标记。调用showTag时,我收到EXC\u BAD\u访问权限: UITextField *text = [[[UITextField alloc] initWithFrame:CGRectMake(195.0, (m*30)+1 , 70.0, 23.0)] autorelease]; text.keyboardType = UIKeyboardTypeDecimalPad; text.tag=MyintValu
UITextField *text = [[[UITextField alloc] initWithFrame:CGRectMake(195.0, (m*30)+1 , 70.0, 23.0)] autorelease];
text.keyboardType = UIKeyboardTypeDecimalPad;
text.tag=MyintValue;
[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];
}
谢谢您正在尝试[NSString stringWithFormat:@“%@,[sender tag]]标记是int值,所以[NSString stringWithFormat:@“%@d”,[sender tag]]…我尝试了这个…没有问题…对我有用…您需要使用
[NSString stringWithFormat:@"%@",[sender tag] ]
[NSString stringWithFormat:@"%@d",[sender tag] ]
[NSString stringWithFormat:@"%i", [sender tag]]
标记是一个int。如果使用%@,它将被解释为指针,并且尝试访问该内存地址(5或22或标记的int值是什么)失败,因为它无效,因此崩溃