HI, 我正在创建一个UItextField,试图在编辑结束时获取标签。我在调用showTag时收到EXC_BAD_ACCESS:
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];
}
谢谢
答案 0 :(得分:0)
你正在尝试
[NSString stringWithFormat:@"%@",[sender tag] ]标签是int值所以
[NSString stringWithFormat:@"%@d",[sender tag] ]...我试过这个......没问题......为我工作......
< / p>
答案 1 :(得分:0)
您需要使用
[NSString stringWithFormat:@"%i", [sender tag]]
标签是一个int。如果使用%@,它将被解释为指针并尝试访问该内存地址(5或22或标记的int值),因为它无效,因此失败。