适用于iPhone的webview上的富文本编辑器

时间:2012-01-30 12:18:57

标签: iphone rich-text-editor

我需要为iPhone应用程序创建一个富文本编辑器(用于文本对齐,字体,粗体,斜体,下划线等)。我听说过将数据存储为HTML并将其呈现在UIWebView中。我想允许用户编辑数据,在我的应用程序中,我使用TapDetectingWindow来检测UIWebView上的触摸(完全按照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;
}

但我的应用程序正在崩溃,并显示消息

tapDetectingWindow.viewToObserve = webView

和报告

* -[UIWindow setViewToObserve:]: unrecognized selector sent to instance 0x4a26b90 

1 个答案:

答案 0 :(得分:3)

经过几个小时的拔毛,这就是答案:您需要编辑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;    
}

我尝试了这个,它与TapDetectingWindow教程的其余部分完美配合!