【发布时间】:2012-01-27 12:50:41
【问题描述】:
当应用程序完成启动时,我尝试从我的 AppDelegate 设置 UITextView。 其实我只是想打开一个文件并将其内容传递给 UITextView。
在我的 ViewController 中,我添加了以下方法:
ViewController.h:
@interface
{
IBOutlet UITextView *textView;
}
- (void)openFile:(NSString *)myString;
ViewController.m:
- (void)openFile:(NSString *)myString
{
textView.text = myString;
}
在我的 AppDelegate 中:
AppDelegate.m:
#import "ViewController.h"
@implementation AppDelegate
- (BOOL)application: [...] didFinishLaunchingWithOptions: [...]
{
ViewController *test = [[ViewController alloc] init];
[test openFile:@"this is a test"];
}
当我尝试从我的 AppDelegate 调用该方法时,它实际上被调用并按预期传递了字符串。
我通过NSLog(@"%@", myString);进行了测试。
但是textView 的值没有改变。
首先我认为可能还有其他问题,所以我在加载视图等后使用 UIButton 调用了该方法。但一切正常,textView 发生了变化。
然后我想,在我从 AppDelegate 调用我的方法后,视图可能会被加载。 我又添加了一些 NSLog,结果发现视图已完全加载,然后我的 AppDelegate 调用了该方法。
所以 AppDelegate 在视图完全加载并传递字符串后调用[test openFile:(NSString *)]。但是我的 textView 的值仍然没有改变。
对此有什么建议吗? 有没有人遇到过同样的问题?
【问题讨论】:
-
你有没有仔细检查过笔尖上的插座是否连接?
-
是的,我做到了。但是我应该在NIB中连接什么来满足这个需求?因为我想在应用程序中完成启动。但是没关系。我解决了这个问题。谢谢
-
请不要给标题加标签,也不要在这样的帖子上签名
标签: ios methods uiviewcontroller uitextview uiapplicationdelegate