无法设置 UIAlertview 事件?
我无法为警报视图设置操作事件。在这里,当我单击警报视图按钮时,它无法执行操作。我的代码有什么问题。
这是我的代码:
-(IBAction)savebuttons
{
if([username.text isEqualToString:@""] && [password.text isEqualToString:@""] && [emailid.text isEqualToString:@""] && [phonenum.text isEqualToString:@""] && [address.text isEqualToString:@""] && [city.text isEqualToString:@""] && [state.text isEqualToString:@""] && [country.text isEqualToString:@""] && [zipcode.text isEqualToString:@""]) {
UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Please enter all the details" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[view show];
[view release];
}
else if([username.text isEqualToString:@""])
{
views = [[UIAlertView alloc] initWithTitle:@"Email ID" message:@"Email ID cannot be blank" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
views.tag=1;
[views show];
[views release];
}
else if([password.text isEqualToString:@""]){
UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"Password" message:@"Password cannot be blank" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
view.tag=2;
[view show];
[view release];
}
else
{
.....
......
}
- (void)alertView:(UIAlertView *)alertViews clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertViews.tag == 1)
{
if(buttonIndex == 0)
{
[username becomeFirstResponder];
NSLog(@"Username");
}
}
if(alertViews.tag == 2)
{
if(buttonIndex == 0)
{
[password becomeFirstResponder];
NSLog(@"Password");
}
}
我只有一个警报视图按钮,例如“确定”。但它没有回应。
I can't set action event for alertview. Here when I click the alertview button it can't be actioned. What's the problem in my code.
Here is my code :
-(IBAction)savebuttons
{
if([username.text isEqualToString:@""] && [password.text isEqualToString:@""] && [emailid.text isEqualToString:@""] && [phonenum.text isEqualToString:@""] && [address.text isEqualToString:@""] && [city.text isEqualToString:@""] && [state.text isEqualToString:@""] && [country.text isEqualToString:@""] && [zipcode.text isEqualToString:@""]) {
UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Please enter all the details" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[view show];
[view release];
}
else if([username.text isEqualToString:@""])
{
views = [[UIAlertView alloc] initWithTitle:@"Email ID" message:@"Email ID cannot be blank" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
views.tag=1;
[views show];
[views release];
}
else if([password.text isEqualToString:@""]){
UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"Password" message:@"Password cannot be blank" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
view.tag=2;
[view show];
[view release];
}
else
{
.....
......
}
- (void)alertView:(UIAlertView *)alertViews clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertViews.tag == 1)
{
if(buttonIndex == 0)
{
[username becomeFirstResponder];
NSLog(@"Username");
}
}
if(alertViews.tag == 2)
{
if(buttonIndex == 0)
{
[password becomeFirstResponder];
NSLog(@"Password");
}
}
I have only one button for alertview like "OK". But it's not responding.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您已将警报视图的委托设置为nil,将其设置为
self
,如果您没有设置委托,则不会调用委托方法you have set delegate of alert views to nil, set it to
self
, if you did not set delegate , delegate methods are not called消息被发送到委托,您将其指定为 nil。将 delegate 设置为 self,就可以了。
The message gets sent to the delegate, which you specified as nil. Set the delegate to self, and it would work.