1

我创建了设置包,我在其中添加了一个文本字段,我需要将 url 从它加载到 uiwebview。我想为其添加默认值,但在更改加载后它不会加载到 uiwebview 中。

请帮忙!

<dict>
            <key>KeyboardType</key>
            <string>URL</string>
            <key>DefaultValue</key>
            <string>http://iscientist.ru/</string>
            <key>Type</key>
            <string>PSTextFieldSpecifier</string>
            <key>Title</key>
            <string>Домашняя страничка 1</string>
            <key>Key</key>
            <string>url1</string>
        </dict>
        <dict>
            <key>KeyboardType</key>
            <string>URL</string>
            <key>DefaultValue</key>
            <string>http://google.com/</string>
            <key>Type</key>
            <string>PSTextFieldSpecifier</string>
            <key>Title</key>
            <string>Домашняя страничка 2</string>
            <key>Key</key>
            <string>url2</string>
        </dict>

和代码:

NSString *settingValue1 = [[NSUserDefaults standardUserDefaults] stringForKey:@"url1"];
NSURL *urlx1 = [NSURL URLWithString:[NSString stringWithFormat:@"%@", settingValue1]];
NSURLRequest *request1 = [NSURLRequest requestWithURL:urlx1];
[_webView loadRequest:request1];

NSString *settingValue2 = [[NSUserDefaults standardUserDefaults] stringForKey:@"url2"];
NSURL *urlx2 = [NSURL URLWithString:[NSString stringWithFormat:@"%@", settingValue2]];
NSURLRequest *request2 = [NSURLRequest requestWithURL:urlx2];
[webView2 loadRequest:request2];
4

1 回答 1

1

您用来获取默认 URL 的密钥是错误的,nik。

代替

NSString *settingValue1 = 
   [[NSUserDefaults standardUserDefaults] stringForKey:@"url1"];

用这个:

NSString *settingValue1 = 
   [[NSUserDefaults standardUserDefaults] stringForKey:@"DefaultValue"];

这将返回http://iscientist.ru/您尝试加载的 URL。

于 2011-11-27T19:23:31.313 回答