我有UIWebview用于显示文章。我需要选择一些文本并发送到另一个viewcontroller UITextView。但是当我安装应用程序时,我选择文本并将其加载到viewcontroller1。但是当我去viewcontroller1时,我选择另一个文本,前一个文本只显示。它没有更新新文本。
代码:
的ViewController:
NSString *selection = [wbCont stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];
NSUserDefaults *userData1 = [NSUserDefaults standardUserDefaults];
[userData1 setObject:selection forKey:@"preferenceName"];
[userData1 synchronize];
[self.navigationController pushViewController:viewcontroller1 animated:YES];
viewcontroller1:
NSString *savedValue = [[NSUserDefaults standardUserDefaults]
stringForKey:@"preferenceName"];
textView.text = [NSString stringWithFormat:@"%@", savedValue];
[self.view addSubview:textView];
答案 0 :(得分:0)
尝试这样做
NSUserDefaults *userData1 = [NSUserDefaults standardUserDefaults];
NSString *savedValue = [userData1 valueForKey:@"preferenceName"];
textView.text = [NSString stringWithFormat:@"%@", savedValue];
[self.view addSubview:textView];
答案 1 :(得分:0)
试试这个:
NSString *selection = [wbCont stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];
NSUserDefaults *userData1 = [NSUserDefaults standardUserDefaults];
[userData1 setValue:selection forKey:@"preferenceName"];
[NSUserDefaults standardUserDefaults] synchronize];
[self.navigationController pushViewController:viewcontroller1 animated:YES];
//查看控制器
NSString *savedValue = [[NSUserDefaults standardUserDefaults]
valueForKey:@"preferenceName"];
UITextView *textView = [UITextView alloc] initWithFrame : cgRectMake(0,0,200,50)]//if not created textview
[self.view addSubview:textView];
textView.text = [NSString stringWithFormat:@"%@", savedValue];