不从设置包(ipad)的默认值加载网址

时间:2011-11-27 14:05:19

标签: xcode ipad uiwebview settings settings.bundle

我创建了设置包,我在其中添加了一个文本字段,我需要将其从网址加载到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];

1 个答案:

答案 0 :(得分:1)

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

而不是

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

使用此:

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

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