-
Notifications
You must be signed in to change notification settings - Fork 3
kttableviewcontroller
KTTableViewController is an iOS view controller designed specifically for Kii Cloud, which provides automatic download and display of objects stored within Kii Cloud. This class is a wrapper for commonly-developed logic; if you know the native iOS class UITableViewController, KTTableViewController will be very familiar!
KTTableViewController also provides some upgrades to the traditional table view, including automatic pagination as well as pull-to-refresh (even for pre-iOS6 devices). This will make your development even easier!
Use the quick start guide to get the view controller in your app in a few short steps - or check out the other sections if you'd like to learn more and start to customize!
As always, you can find full documentation and edit the source within the KiiToolkit repository.
Want a complete tutorial, along with working sample code? Check out a full tutorial in our documentation
Get the KTTableViewController implemented in a few short minutes using the steps below:
1. Get Started with Kii Cloud (Skip this section if you already have KiiSDK in your application)
Simply follow the instructions found here to:
- Register for Kii Cloud (don't worry, it's FREE!)
- Create an app in the developer portal
- Download the Kii Cloud SDK
- Import the SDK into your application
**2\. Add KiiToolkit** (Skip this section if you already have the latest version of KiiToolkit in your application)
Follow the steps here to import the KiiToolkit and its dependencies into your app
**3\. Create a KTTableViewController class**
It might look something like:
MyTableViewController.h
#import <UIKit/UIKit.h>
#import "KiiToolkit.h"
@interface MyTableViewController : KTTableViewController
@end
MyTableViewController.m
#import "MyTableViewController.h"
#import <KiiSDK/Kii.h>
@implementation MyTableViewController
@end
**4\. Set up the query**
Since KTTableViewController pulls its data from Kii Cloud, we need to set up a KiiQuery object to know what data to use.
To learn more about KiiQuery, see our docs here: http://documentation.kii.com/en/guides/ios/managing-data/object-storages/querying/
The following is just an example, but something similar should be placed somewhere in your MyTableViewController.m
, potentially in a viewDidAppear:
method:
// this defines the query
KiiQuery *query = [KiiQuery queryWithClause:nil];
[query sortByDesc:@"myTimestamp"];
self.query = query;
// and this defines the bucket
self.bucket = [[KiiUser currentUser] bucketWithName:@"myBucket"];
// we also want to refresh the table with the latest query and bucket
[self refreshQuery];
Note: The bucket is dependent on
[KiiUser currentUser]
, so a user must be authenticated prior to setting up the table in this case
**5\. Implement the cell creation method**
Enter the following method in your MyTableViewController.m
class implementation:
- (UITableViewCell*) tableView:(UITableView *)tableView
cellForKiiObject:(KiiObject *)object
atIndexPath:(NSIndexPath *)indexPath
{
// implement a cell creator
}
An example implementation may look something like this:
- (UITableViewCell*) tableView:(UITableView *)tableView
cellForKiiObject:(KiiObject *)object
atIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"MyCell";
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:identifier];
// set our label based on the KiiObject value
cell.textLabel.text = [object getObjectForKey:@"myKiiCloudKey"];
return cell;
}
The KTTableViewController class offers a number of different customizable features. Some are shown below, but check out the full documentation (in the Documentation/html directory of the repository) to find everything that can be customized.
This will automatically retrieve the next set of objects in the query once the user has scrolled to the bottom of the page. The loading indicator is handled automatically, and you can toggle this functionality on/off. The default is ON.
You can turn auto-pagination off using the following method call from within your KTTableViewController subclass
self.paginationEnabled = NO;
This will set a limit to the number of items retrieved per page. Set this to an integer value using an assignment within your KTTableViewController as shown below. The maximum value allowed is 100.
self.pageSize = 10;
This will utilize the popular pull-to-refresh mechanism to retrieve the latest results. It is important to note that this will work on pre-iOS6 devices. The loading is handled automatically, and you can toggle this functionality on/off. The default is ON.
You can turn this mechanism off using the following method call from within your KTTableViewController subclass
self.refreshControlEnabled = NO;
You can also customize the view that currently shows a label with the title 'Pull to refresh...' by accessing the property refreshNoticeView
within your KTTableViewController subclass. Utilize this attribute in order to match the look and feel of your application.