Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
This example describes some methods of working with notes in regular report. After starting the example the following operations are executed:
Regular report sheet viewer view is retrieved.
Number of notes in regular report is retrieved from sheet viewer view.
A new note is added to regular report.
A new report viewer delegate is created.
The created regular report note is opened by means of report viewer delegate.
The note is retrieved from sheet viewer by specified index.
The obtained note is hidden by means of the <PopoverContainedControllerProtocol>.popover property in report viewer delegate.
The note obtained by specified index is deleted.
It is required to add the following file in the Displaying of Regular Report example:
ProceduralDelegateImpl.h/.m. Report viewer delegate.
Executing the example requires to create a report viewer delegate class, which implements methods and properties of the <ProceduralDelegate> and <PopoverContainedControllerProtocol> protocols, to add class header file to source code of the ViewController class (see the Displaying of Regular Report section), and also to place the following code in the body of the executeExample method of the ViewController class:
// Get regular report object MAProceduralReportViewController *proceduralReportController = (MAProceduralReportViewController *)m_controller; // Get array of regular report views NSArray *dataViewControllers = [proceduralReportController dataViewControllers]; // Parse regular report views in cycle for( UIViewController *controller in dataViewControllers) { // Check if the current view is a regular report sheet viewer if([controller isMemberOfClass:[MAProceduralReportDataViewController class]]) { // Get sheet viewer view MAProceduralReportDataViewController *dataViewController =(MAProceduralReportDataViewController *)controller; // Display number of regular report notes in the development environment console NSLog(@"Number of regular report notes: %d", [dataViewController notesCount]); // Set note creation time, specify 12:00:00 as the current time NSDateComponents *components = [NSDateComponents new]; [components setHour:12]; [components setMinute:0]; [components setSecond:0]; NSCalendar *calendar = [NSCalendar currentCalendar]; NSDate *date = [calendar dateFromComponents:components]; // Set point, in which a note is created CGPoint point = CGPointMake(50, 100); // Add a note to regular report [dataViewController addNote:point withText:@"Note" timestamp:[date timeIntervalSince1970]]; // Display number of regular report notes after adding a note in the development environment console NSLog(@"Number of notes after adding a note: %d", [dataViewController notesCount]); // Create a report viewer delegate ProceduralDelegateImpl *proceduralDelegateImpl = [[ProceduralDelegateImpl alloc] initWithProceduralReportDataViewController:dataViewController]; // Open note with specified index [proceduralDelegateImpl openNoteAtIndex:0]; // Call method that continues example execution after a pause [self performSelector:@selector(continueExample:) withObject:proceduralDelegateImpl afterDelay:5]; } }
It is also required to add the following methods with their implementation in the ViewController class:
// Continues example execution - (void) continueExample:(ProceduralDelegateImpl *)proceduralDelegateImpl { // Get note by specified index Note *note = [proceduralDelegateImpl.dataViewController noteByIndex:0]; // Hide note [proceduralDelegateImpl cancelNote]; // Change note [proceduralDelegateImpl.dataViewController editNoteAtIndex:0 point:CGPointMake(150, 100) text:@"Edited note" timestamp:[note timestamp]]; // Open changed note [proceduralDelegateImpl openNoteAtIndex:0]; // Delete note after a pause [self performSelector:@selector(deleteNote:) withObject:proceduralDelegateImpl afterDelay:5]; }
// Deletes note - (void) deleteNote:(ProceduralDelegateImpl *)proceduralDelegateImpl { // Hide note [proceduralDelegateImpl cancelNote]; // Delete note by specified index [proceduralDelegateImpl.dataViewController removeNoteWithIndex:0]; // Display number of regular report notes after deleting a note in the development environment console NSLog(@"Number of notes after deleting a note: %d", [proceduralDelegateImpl.dataViewController notesCount]); }
After executing the example the mobile device screen displays a note added to the regular report:
The edited note, for which a new text value and screen position is set, is displayed in five seconds after starting the example:
Five seconds later the displayed note is hidden and deleted, after that the regular report is restored to its initial view. The development environment console also displays the number of regular report notes after adding and deleting the new note:
Number of regular report notes: 0
Number of notes after adding a note: 1
Number of notes after deleting a note: 0
See also: