我正在尝试在 UIAlertview 中添加 UITextfield,以便用户可以输入所需的文本,并在单击提交后必须将相应的数据发送到 Web 服务。
Viewcontroller 是 320*600 框架集,所以我有滚动视图来显示整个内容。
运行时,按下“下一步”按钮时,显示带有文本字段的警报视图没有问题,但是当我单击警报视图中的“提交”按钮或“取消”按钮时,视图控制器的滚动视图不起作用,但“导航栏中用于移动到上一个控制器的“后退”按钮效果很好。
带有文本字段的 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];
}
这可能是什么原因以及滚动视图无法正常工作的原因。
更新:
“提交”按钮的操作是,
-(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];
}
}