1

我正在尝试在 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];

}

}
4

2 回答 2

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];

    }
于 2013-09-20T08:25:48.073 回答
0

只需检查与取消和提交按钮链接的操作。可能会出现一些错误,否则滚动视图会起作用。

于 2013-09-19T10:36:10.660 回答