我有UIWebView用于显示HTML文章。当用户触摸UIWebView中的某个区域时,将显示UIMenuController。然后用户选择它显示UITextView的注释按钮,然后用户就可以编写一些文本,之后用户可以将文本存储到那个触摸区域,如Documents by Readdle app。我创建了最多写文本并保存到数据库。保存文本后,我需要在触摸区域上显示按钮。如何启用按钮?
UIWEbView显示文章页面:
在显示longpress UIMenuController后,然后选择备注
选择笔记后,会出现UITextView以写入一些笔记,然后单击“完成”按钮,UItextView将删除,然后将显示UIWebView。
我需要在uiwebview longpress位置显示小按钮或图标。在UIWebView上方,位置为Commences
。在接近开始的文本中,我需要在单击完成按钮
- (void)viewDidLoad
{
[wbCont loadHTMLString:webString baseURL:nil];
wbCont.userInteractionEnabled=YES;
[self.view addSubview:wbCont];
menuItem = [[UIMenuItem alloc] initWithTitle:@"Notes" action:@selector(note:)];
[items addObject:menuItem];
}
在longpress UIMenuItem打开并单击note后再打开UItextView
- (void)note:(id)sender{
NSLog(@"Note");
self.navigationController.navigationBarHidden=YES;
txtview = [[UITextView alloc]initWithFrame:CGRectMake(0,0,320,568)];
txtview.font = [UIFont fontWithName:@"Helvetica" size:12];
txtview.font = [UIFont boldSystemFontOfSize:12];
txtview.backgroundColor = [UIColor whiteColor];
txtview.scrollEnabled = YES;
txtview.pagingEnabled = YES;
txtview.editable = YES;
[self.view addSubview:txtview];
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(click:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Done" forState:UIControlStateNormal];
button.frame = CGRectMake(240.0, 20.0, 60.0, 40.0);
[txtview addSubview:button];
}
然后点击完成按钮我保存文字:
-(void)click:(id)sender{
NSLog(@"done");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
// NSString *documentsDirectory = [paths objectAtIndex:1];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"ohs.sqlite"];
NSLog(@"filepath %@",path);
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
const char *sql = [[NSString stringWithFormat:@"SELECT textnotes FROM textnote where textnote = '%@'",txtview.text] cStringUsingEncoding:NSUTF8StringEncoding];
NSLog(@"sql is %s",sql);
BOOL favExist = false;
sqlite3_stmt *statement, *addStmt;
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
// We "step" through the results - once for each row.
while (sqlite3_step(statement) == SQLITE_ROW) {
favExist = true;
}
}
if(!favExist){
const char *sqlInsert = [[NSString stringWithFormat:@"insert into textnote (textnotes ) values ('%@')", txtview.text] cStringUsingEncoding:NSUTF8StringEncoding];
NSLog(@"sql insert is %s",sqlInsert);
// [catID release];
if(sqlite3_prepare_v2(database, sqlInsert, -1, &addStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
if(SQLITE_DONE != sqlite3_step(addStmt))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
}else {
}
}
[txtview removeFromSuperview];
[button removeFromSuperview];
}
保存文本后,我删除了textview,按钮。然后将显示UIWebView。 UIwebView tocuh定位如何显示用于通过readdle app保存文本的按钮。