【发布时间】:2011-11-27 15:57:36
【问题描述】:
它是一个单视图应用程序,我只是在它上面添加一个按钮 当我单击按钮时,它将显示键盘。 而且我无法在 onBtn 函数中自动释放 TSAlertView。 谁能告诉我为什么,我真的很困惑。
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(30, 30, 100., 50);
[btn setTitle:@"Test" forState:UIControlStateNormal];
[btn addTarget:self action:(@selector(onBtn:)) forControlEvents: UIControlEventTouchUpInside];
[btn setBackgroundColor:UIColor.greenColor];
[self.view addSubview:btn];
}
-(void)onBtn:(id)sender{
TSAlertView* av = [[TSAlertView alloc] init];
av.title = @"Test";
av.message = @"This is a test";
[av addButtonWithTitle:@"cancel"];
[av addButtonWithTitle:@"rename"];
av.style =TSAlertViewStyleInput;
av.buttonLayout = TSAlertViewButtonLayoutNormal;
av.usesMessageTextView =NO;
av.width = 0.0;
av.maxHeight = 0.0;
[av show];
}
【问题讨论】:
-
TSAlertView 默认为普通视图。您的代码中必须有其他原因导致此问题。你能展示你的 onBtn 方法的其余部分吗?
-
@Havt 我已经发布了剩下的 onBtn 方法,请帮帮我,谢谢
-
键盘出现是因为某个需要键盘的 UI 对象已成为第一响应者。
标签: iphone uibutton ios5 xcode4.2