我想要当用户在textfiled中输入错误值时显示alert并且它使textfield emty以及按钮标题为空。在我的代码中textfield为空但按钮没有得到空值
下面的是我的代码
if (monthText>totalnumber) {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Value Must Be Less than total number of dogs " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
NSString *titleMonth =@"0";
[cereniaButton setTitle:@"" forState:UIControlStateNormal];
cereniaTextField.text=@"";
}
int year=12;
int monthButtonTitle=monthText*year;
NSString *titleMonth =[NSString stringWithFormat:@"%d",monthButtonTitle];
[cereniaButton setTitle:titleMonth forState:UIControlStateNormal];
答案 0 :(得分:0)
如果您直接指定
,会发生什么[btn setTitle:@“”forState:UIControlStateNormal];
答案 1 :(得分:0)
将标题设置为按钮
后写下此行[self.view setNeedsDisplay];
答案 2 :(得分:0)
你正在重置标题,但是你的标题将成为ripopolate。
试
if (monthText>totalnumber) {
//...yourcode...
return;
}
让我知道
答案 3 :(得分:0)
可能是你缺少连接按钮与文件所有者,试试这个:
- (void)textFieldDidEndEditing:(UITextField *)textField
int txtValue = [textField.text intValue];
if(txtValue < 10)
btn.titleLabel.text = [NSString stringWithFormat:@"%d",txtValue];
else
{
btn.titleLabel.text = [NSString stringWithFormat:@""];
}
}
- (BOOL)textFieldShouldReturn: (UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}