I have UIWebView for displays HTML articles. When user touch some area in UIWebView, UIMenuController will display. Then user select note button it displays UITextView, then user can able to write some text, after that user can store the text to that touched area like Documents by Readdle app. I created upto write text and save to database. After saving text i need to show button on touched area. How to enable button?
UIWEbView displays the articles pages:
After longpress UIMenuController will displays, then choose notes
After choosing notes UITextView will appear for write some notes, then click Done button the UItextView will remove then UIWebView will appear.
I need to displays the small button or icon in uiwebview longpress position. In Above UIWebView position is Commences
. In near commences text i need to display the small icon after click Done button
- (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];
}
After longpress UIMenuItem will open and click note then open 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];
}
Then click Done button i save the text:
-(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];
}
After saving text i remove the textview, button. Then the UIWebView will display. UIwebView tocuh position how to displays the button for saving text like Documents by readdle app.