Val*_*lli 5 iphone rich-text-editor
我需要为 iPhone 应用程序创建一个富文本编辑器(用于文本对齐、字体、粗体、斜体、下划线等)。我听说过将数据存储为 HTML 并将其呈现在 UIWebView 中。我想允许用户编辑数据,在我的应用程序中,我使用 TapDetectingWindow 来检测 UIWebView 上的触摸(完全如这里所述)。
- (id)init {
self = [super init];
if (self) {
tapDetectingWindow = (TapDetectingWindow *)[[UIApplication sharedApplication].windows objectAtIndex:0]; //mWindow, variable reference to TapDetectingWindow
tapDetectingWindow.viewToObserve = webView;
tapDetectingWindow.controllerThatObserves = self;
webView = [[UIWebView alloc] init];
[webView setFrame:CGRectMake(0, 0, 340, 1900)];
[webView setTag:1];
[webView addSubview:keyboardText];
[webView setDelegate:self];
[webView setOpaque:0.0];
[webView loadHTMLString:htmlString baseURL:NULL];
[self.view addSubview:webView];
keyboardText = [[UITextField alloc] init];
keyboardText.autocorrectionType = UITextAutocorrectionTypeNo;
[keyboardText setDelegate:self];
[self.view addSubview:keyboardText];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
但是我的应用程序崩溃了,并显示消息
tapDetectingWindow.viewToObserve = webView
Run Code Online (Sandbox Code Playgroud)
和一份报告
* -[UIWindow setViewToObserve:]: unrecognized selector sent to instance 0x4a26b90
Run Code Online (Sandbox Code Playgroud)
经过几个小时的绞尽脑汁,答案如下:您需要编辑 AppDelegate 的 .m 文件以使 TapDetectingWindow 正常工作:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController* vc = self.window.rootViewController;
self.window = [[TapDetectingWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = vc;
return YES;
}
Run Code Online (Sandbox Code Playgroud)
我尝试了这个,它与TapDetectingWindow教程的其余部分完美配合!
| 归档时间: |
|
| 查看次数: |
820 次 |
| 最近记录: |