I have just started learning how to create today view widgets on iOS8. I created a new target for the extension. Next step i deleted the default viewcontroller
and classes and created a new UITableViewController
and it's corresponding methods. I implemented the following:
#import "TableViewController.h"
#import <NotificationCenter/NotificationCenter.h>
@interface TableViewController () <NCWidgetProviding>
{
NSArray *nameArray;
}
@end
@implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
nameArray = [[NSArray alloc]initWithObjects:@"joey",@"jack",@"jill", nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 3;
}
- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
completionHandler(NCUpdateResultNewData);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.textLabel.text = [nameArray objectAtIndex:indexPath.row];
return cell;
}
I have also changed the table size to freeform
and set its height to 300px. But i get nothing in return. The widget comes up empty.