Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
This example describes creating a bookmark, adding it to the list of regular report bookmarks, and also shows working with a table and its cells containing bookmark names.
Executing the example requires to place the following code in the body of the executeExample method of the ViewController class (see the Displaying of Regular Report section):
// Get controller for working with regular report MAProceduralReportDataViewController<MADataViewControllerProtocol> *contr = (MAProceduralReportDataViewController<MADataViewControllerProtocol> *)[(MAProceduralReportViewController *)m_controller activeDataViewController]; // Create a bookmark Bookmark *bookmark = [[Bookmark new] autorelease]; // Determine bookmark name and its location [bookmark initWithName:@"Bookmark 1" offset:CGPointMake(150, 200)]; // Link bookmark to the last page [bookmark setPage: [contr pagesCount] - 1]; // Determine new location of bookmark taking into account the specified page CGPoint offset; offset.x = [bookmark offset].x; float pageOffset = [bookmark page]*[contr pdfView].scrollView.contentSize.height / [contr pagesCount]; offset.y = ([bookmark offset].y + pageOffset)* [contr pdfView].scrollView.zoomScale; [bookmark setOffset:offset]; // Add the current name to bookmark name NSDateFormatter *dateFormat = [[NSDateFormatter new] autorelease]; [dateFormat setDateFormat:@"HH:mm:ss"]; [bookmark setName:[NSString stringWithFormat:@"%@ %@", [bookmark name], [dateFormat stringFromDate: [NSDate date]]]]; // Create a collection of bookmarks NSMutableArray *bookmarks = [[NSMutableArray new] autorelease]; [bookmarks addObject:bookmark]; // Set new collection of bookmarks [(MAProceduralReportDataViewController*)contr setValue:bookmarks forKeyPath:@"currentDocument.bookmarks"]; // Go to the created bookmark [(MAProceduralReportDataViewController*)contr openBookmark:0]; // Create a controller for bookmark selection BookmarksViewController *bookmarksViewCtrl = [[BookmarksViewController alloc] initWithStyle:UITableViewStylePlain]; // Set delegate for viewing reports [bookmarksViewCtrl setDelegate:contr]; // Set window size for bookmark selection [bookmarksViewCtrl setContentSizeForViewInPopover: CGSizeMake(250, 300)]; // Get data view as a bookmark table UITableView *tableView = [bookmarksViewCtrl tableView]; // Determine path to cell with a bookmark NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:0 inSection:0]; // Get cell with bookmark BookmarkTableViewCell *cell1 = (BookmarkTableViewCell*)[bookmarksViewCtrl tableView:tableView cellForRowAtIndexPath:indexPath1]; // Get text field in cell UITextField *textField1 = (UITextField *)[cell1 valueForKey:@"textField"]; NSLog(@"Bookmark name: %@", textField1.text); // Rename bookmark [[cell1 delegate] bookmarkCell:cell1 changeTitle:@"Bookmark 2"]; // Get cell with bookmark again and corresponding text field BookmarkTableViewCell *cell2 = (BookmarkTableViewCell*)[bookmarksViewCtrl tableView:tableView cellForRowAtIndexPath:indexPath1]; UITextField *textField2 = (UITextField *)[cell2 valueForKey:@"textField"]; NSLog(@"Bookmark name: %@", textField2.text); // Edit text in field of the cell corresponding to bookmark [cell2 setTitle:@"Bookmark 3"]; UITextField *textField3 = (UITextField *)[cell2 valueForKey:@"textField"]; NSLog(@"Bookmark name: %@", textField3.text); // Deny bookmark text editing [cell2 setEditingStyle:NO]; // Display table with bookmarks in a popup window UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:bookmarksViewCtrl]; [popoverController presentPopoverFromRect:CGRectMake(bookmark.offset.x + 50, bookmark.offset.y + 50, 20, 30) inView:[contr pdfView].scrollView permittedArrowDirections:NULL animated:YES];
After executing the example a bookmark is created for the last page of regular report document. A popup window is displayed containing a table with bookmarks:
The bookmark is renamed twice, these events are displayed as messages in the development environment console:
Bookmark name: Bookmark 1 09:34:06
Bookmark name: Bookmark 2
Bookmark name: Bookmark 3
Firstly, the bookmark is renamed, secondly, cell text is changed that corresponds to the specified bookmark. If we enable bookmark editing, that is, cell the setEditingStyle method with the YES parameter, the last change is ignored:
See also: