I need to create a rich text editor (for text alignment, fonts, bold, italics, underlining etc) for an iPhone app. I have heard of storing the data as HTML and rendering it in a UIWebView. I want to allow the user to edit the data and in my app I am using TapDetectingWindow to detect touches on a UIWebView (exactly as detailed here).
- (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;
}
But my app is crashing, with the message
tapDetectingWindow.viewToObserve = webView
and a report
* -[UIWindow setViewToObserve:]: unrecognized selector sent to instance 0x4a26b90
After a few hours of hair pulling, here’s the answer: you need to edit your AppDelegate’s .m file to get the TapDetectingWindow to work properly:
I tried this and it’s working perfectly with the rest of the TapDetectingWindow tutorial!