我正在尝试在UIAlertview中添加UITextfield,以便用户可以输入所需的文本,在单击提交后,相应的数据必须发送到Web服务。
Viewcontroller是320 * 600的框架集,所以我有滚动视图来显示整个内容。
在运行时,当按下“下一个”按钮时,显示带有文本字段的alertview没有任何问题,但是当我点击alertview中的“提交”按钮或“取消”按钮时,viewcontroller的scrollview无效,但导航栏中用于移动到上一个控制器的“后退”按钮效果很好。
带有文本字段的alertview代码是,
- (IBAction)next:(id)sender
{
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Enter your changes"
message:nil
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Submit Changes", nil];
[message setAlertViewStyle:UIAlertViewStylePlainTextInput];
[message show];
}
这可能是造成这种情况的原因以及为什么scrollview无法正常工作。
更新:
“提交”按钮的操作是,
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
UIAlertView *approval = [[UIAlertView alloc]initWithTitle:@"success" message:@"Your request is updated " delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[approval show];
text = [[alertView textFieldAtIndex:0] text];
NSLog(@"passed value %@",text);// text returns the entered value
}
NSURL *url = [NSURL URLWithString:@"http://*******************************"];
NSMutableURLRequest *urlRequest =[[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSString * log= [NSString stringWithFormat:@"key=%@&Action=Preview&deal=%d&status=%d,comment=%@",session,value,11,text];
[urlRequest setHTTPBody:[log dataUsingEncoding:NSUTF8StringEncoding]];
[urlRequest setHTTPMethod:@"POST"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
if(connection)
{
NSLog(@"Request for change");
responseData = [[NSMutableData alloc] init];
}
}
答案 0 :(得分:0)
只需检查与取消和提交按钮关联的操作。可能会出现一些错误,否则滚动视图会起作用。
答案 1 :(得分:0)
尝试使用此代码。将submit_pressed操作链接到提交按钮。点击提交时,将弹出警报视图,并将值发送到给定的URL链接。单击确定后查看确定将显示普通视图。它与滚动视图无关。
-(IBAction)Submit_pressed
{
UIAlertView *approval = [[UIAlertView alloc]initWithTitle:@"success" message:@"Your request is updated " delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[approval show];
text = [[alertView textFieldAtIndex:0] text];
NSLog(@"passed value %@",text);// text returns the entered value
NSURL *url = [NSURL URLWithString:@"http://*******************************"];
NSMutableURLRequest *urlRequest =[[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSString * log= [NSString stringWithFormat:@"key=%@&Action=Preview&deal=%d&status=%d,comment=%@",session,value,11,text];
[urlRequest setHTTPBody:[log dataUsingEncoding:NSUTF8StringEncoding]];
[urlRequest setHTTPMethod:@"POST"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
if(connection)
{
NSLog(@"Request for change");
responseData = [[NSMutableData alloc] init];
}