ios - 按下 UIButton 时加载 UIWebview

标签 ios objective-c uiwebview

我正在为 iPhone 开发一个简单的测试应用程序。我想点击一个按钮来改变URLwebview ,然后加载新的 URL。这是我的代码:

NSString *nurl = [NSString stringWithFormat: @"http://www.abc.com/abc.aspx?SN=%@&fdate=%@&tdate=%@", SNstr, fDate, tDate];

NSLog(@"################: %@", nurl);

NSURL *url = [NSURL URLWithString:nurl];

NSLog(@"################: %@", url);

NSURLRequest *req = [NSURLRequest requestWithURL:url];



[Logs loadRequest:req];

它在 viewDidLoad 内部运行良好.
我将它移动到一个按钮中:
-(IBAction)CheckLog:(id)sender
{
    // codes here
}

当我按下按钮时,它会给出 nurl的值正确,但 url的值为空。所以 UIWebView 上没有任何改变 Logs .

为什么会这样,当代码在 viewDidLoad 中正确运行时?

最佳答案

您的按钮操作将是这样的......

-(IBAction)CheckLog:(id)sender
{
[[NSURLCache sharedURLCache] removeAllCachedResponses];

 NSString *nurl = [NSString stringWithFormat: @"http://www.abc.com/abc.aspx?SN=%@&fdate=%@&tdate=%@", SNstr, fDate, tDate];

   NSURL *url = [NSURL URLWithString: [nurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ];

   // NSURL *theURL = [NSURL URLWithString:@"https://www.google.co.in/"]; // Your new URL 

    [self.myWebView loadRequest:[NSURLRequest requestWithURL:url]];
}

关于ios - 按下 UIButton 时加载 UIWebview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17084168/

相关文章:

ios - 如何在条形图数据上设置 x 轴 - ios-charts?

ios - 无法通过 faSTLane 在 Crashlytics Beta 发行说明中包含表情符号

objective-c - 使用核心动画旋转 UIImageView

objective-c - IOS 中的垂直和水平滚动

ios - UIKeyboardWillShowNotification 错误地更改了 UIWebView 的框架

ios - indexpath.row 是否负责迭代数组?

iphone - APNs Urban Airship Client Side Integration上的Xcode 4.0中没有此类文件或目录编译器错误?

iphone - 当对象移动到特定帧时如何停止 UIPanGestureRecognizer

jquery - ios 6 uiwebview 使用 jquery scrolltop 滚动页面时显示背景

javascript - 在 iOS 中使用带有 Javascript 的 UIWebView 到 ~/Documents/folder 的相对路径