@@ -16,6 +16,7 @@ @interface StripedTextTableViewController () <UISearchResultsUpdating>
1616@property (nonatomic , strong ) NSNumberFormatter *decimalNumberFormatter;
1717@property (nonatomic , assign ) NSUInteger numberOfTextRowsNotLoaded;
1818
19+ @property (nonatomic , strong ) UIBarButtonItem *shareItem;
1920@property (nonatomic , strong ) UIBarButtonItem *trashItem;
2021@property (nonatomic , strong ) UISearchController *searchController;
2122
@@ -72,10 +73,18 @@ - (void)viewDidLoad {
7273 });
7374 }
7475
76+ NSMutableArray <UIBarButtonItem *> *rightBarButtonItems = [NSMutableArray arrayWithCapacity: 2 ];
77+
78+ if (self.allowShare ) {
79+ [rightBarButtonItems addObject: self .shareItem];
80+ }
81+
7582 if (self.allowTrash ) {
76- self. navigationItem . rightBarButtonItem = self.trashItem ;
83+ [rightBarButtonItems addObject: self .trashItem] ;
7784 }
7885
86+ self.navigationItem .rightBarButtonItems = rightBarButtonItems;
87+
7988 if (self.allowSearch ) {
8089 self.navigationItem .hidesSearchBarWhenScrolling = YES ;
8190 self.navigationItem .searchController = self.searchController ;
@@ -242,6 +251,17 @@ - (void)resetAutoReload {
242251 dispatch_resume (eventSource);
243252}
244253
254+ - (void )shareItemTapped : (UIBarButtonItem *)sender {
255+ UIActivityViewController *activityViewController = [[UIActivityViewController alloc ] initWithActivityItems: @[[NSURL fileURLWithPath: self .entryPath]] applicationActivities: nil ];
256+ if (@available (iOS 16.0 , *)) {
257+ activityViewController.popoverPresentationController .sourceItem = sender;
258+ } else {
259+ // Fallback on earlier versions
260+ activityViewController.popoverPresentationController .barButtonItem = sender;
261+ }
262+ [self presentViewController: activityViewController animated: YES completion: nil ];
263+ }
264+
245265- (void )trashItemTapped : (UIBarButtonItem *)sender {
246266 UIAlertController *alert = [UIAlertController alertControllerWithTitle: NSLocalizedString(@" Confirm" , @" StripedTextTableViewController" ) message: [NSString stringWithFormat: NSLocalizedString(@" Do you want to clear this log file “%@ ”?" , @" StripedTextTableViewController" ), [self .entryPath lastPathComponent ]] preferredStyle: UIAlertControllerStyleAlert];
247267 [alert addAction: [UIAlertAction actionWithTitle: NSLocalizedString(@" Cancel" , @" StripedTextTableViewController" ) style: UIAlertActionStyleCancel handler: ^(UIAlertAction *_Nonnull action) {
@@ -398,6 +418,13 @@ - (void)updateSearchResultsForSearchController:(UISearchController *)searchContr
398418
399419#pragma mark - UIView Getters
400420
421+ - (UIBarButtonItem *)shareItem {
422+ if (!_shareItem) {
423+ _shareItem = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem: UIBarButtonSystemItemAction target: self action: @selector (shareItemTapped: )];
424+ }
425+ return _shareItem;
426+ }
427+
401428- (UIBarButtonItem *)trashItem {
402429 if (!_trashItem) {
403430 _trashItem = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem: UIBarButtonSystemItemTrash target: self action: @selector (trashItemTapped: )];
0 commit comments