Setting up DocumentTableViewController.h
-
Open the file DocumentTableViewController.h in Xcode. After the
#import statements you added in the previous tutorial, add the following import.
#import "AlfrescoDocumentFolderService.h"
So your #imports look like the following:
#import <UIKit/UIKit.h> #import "AlfrescoSession.h" #import "AlfrescoNode.h" #import "AlfrescoDocumentFolderService.h"
The SkyVaultDocumentFolderService class needs to be included as this service will be used to retrieve information about the selected node.
-
Next you need to add a property to store the
SkyVaultDocumentFolderService instance that will be required. You
will need to add the following code below the properties you added in the previous
tutorial:
@property (strong, nonatomic) SkyVaultDocumentFolderService *documentFolderService;
The DocumentTableViewController.h code should now be as follows:
#import <UIKit/UIKit.h> #import "AlfrescoSession.h" #import "AlfrescoNode.h" #import "AlfrescoDocumentFolderService.h" @interface DocumentTableViewController : UITableViewController @property (strong, nonatomic) SkyVaultNode *node; @property (strong, nonatomic) id<AlfrescoSession> session; @property (strong, nonatomic) SkyVaultDocumentFolderService *documentFolderService; - (id)initWithSession:(id<AlfrescoSession>)createdSession andNode:(AlfrescoNode *)nodeToBeDisplayed; @end
Further cleanup of DocumentTableViewController.m
- Open DocumentTableViewController.m into Xcode. Navigate to the method - (id)initWithStyle:(UITableViewStyle)style, which will be the first method definition. Remove this method completely. You do not need this method as this view is initialized with the method initWithSession:andNode:
-
Navigate to #pragma mark - Table view delegate at the bottom of
DocumentTableViewController.m.
You are not going to need this method as it is a callback used when a row is selected. In this view you don't need to carry out any specific actions if a row is selected, you are just going to view information about the node selected in the previous view.
-
Remove the following code:
#pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Navigation logic may go here. Create and push another view controller. /* <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; // ... // Pass the selected object to the new view controller. [self.navigationController pushViewController:detailViewController animated:YES]; */ }
-
Navigate to the method - (void)viewDidLoad. You will see commented
out code within the method. Remove the following code completely:
// Uncomment the following line to preserve selection between presentations. // self.clearsSelectionOnViewWillAppear = NO; // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem;
This code will not be required for the purposes of this tutorial. The application does not need to deal with row selections in this particular view, and no table items will be edited.
The - (void)viewDidLoad method should now match the following code:
- (void)viewDidLoad { [super viewDidLoad]; }
Settings section headings for the node detail view
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { NSString *heading = [[NSString alloc] init]; switch (section) { case 0: heading = @"Summary"; break; case 1: heading = @"General"; break; case 2: heading = @"Comments"; break; case 3: heading = @"Tags"; break; case 4: heading = @"Versions"; break; default: break; } return heading; }
From this you can see there will be sections in the table for a summary, and general information. Also comments, tags, and document versions will be displayed for the node if available.
Add code to return the number of table sections
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 5; }
There are going to be five table sections in this view, so 5 is returned.
Add code to return the number of rows in each table view section
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSInteger numRows; switch (section) { case 0: // Summary section numRows = 3; break; case 1: // General section numRows = 1; break; case 2: // Comments section numRows = 1; break; case 3: // Tags section numRows = 1; break; case 4: // Versions section numRows = 1; break; default: numRows = 0; break; } return numRows; }
How to add code to set cell content
-
Open DocumentTableViewController.m in Xcode and navigate to
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath. Modify the method to match
the following code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // Configure the cell... if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; // SECTION 0 - Summary if (indexPath.section == 0) { switch (indexPath.row) { case 0: cell.textLabel.text = self.node.name; break; case 1: if (self.node.isDocument == TRUE) { cell.textLabel.text = @"isDocument == TRUE"; } else if (self.node.isFolder == TRUE) { cell.textLabel.text = @"isFolder == TRUE"; } else { cell.textLabel.text = @"Not document or folder."; } break; case 2: cell.textLabel.text = @"Latest version label will go here"; break; default: break; } } // SECTION 1 - General if (indexPath.section == 1) { cell.textLabel.text = @"General info will go here."; } // SECTION 2 - Comments if (indexPath.section == 2) { cell.textLabel.text = @"Comments will go here."; } // SECTION 3 - Tags if (indexPath.section == 3) { cell.textLabel.text = @"Tags will go here."; } // SECTION 4 - Versions if (indexPath.section == 4) { cell.textLabel.text = @"Versions will go here."; } } return cell; }
This code sets the cell text depending on which row is being drawn. Note that for the general, comments, tags, and versions sections you just set placeholder text. More useful code will be added for these sections in later tutorials.
For now, focus on the following snippet for the summary section:
if (indexPath.section == 0) { switch (indexPath.row) { case 0: cell.textLabel.text = self.node.name; break; case 1: if (self.node.isDocument == TRUE) { cell.textLabel.text = @"isDocument == TRUE"; } else if (self.node.isFolder == TRUE) { cell.textLabel.text = @"isFolder == TRUE"; } else { cell.textLabel.text = @"Not document or folder."; } break; case 2: cell.textLabel.text = @"Latest version label will go here"; break; default: break; } }
There are three rows in this section. The first row (case 0) will display the node name. The second row (case 1) will display whether the node is a document, a folder, or something else. The third row (case 2) will be used to display the version label for the latest version of the document, but currently is a placeholder - this feature will be added in a later tutorial.
-
Build and run your code. When you select a node you will now see something similar to
the following:
In this tutorial you added code to HelloRepo to display node information in a new view.