I have recently added a Widget to my application, or have tried to. When I run it the widget shows in the notification center but it appears collapsed. I have confirmed the viewDidLoad is not being called by using NSLog. Any ideas why its not loading? Thanks.
Edit: it seems the problem is the label won't be added I had to create everything in the interface builder.
.h file
#import <UIKit/UIKit.h>
#import <NotificationCenter/NotificationCenter.h>
@interface TodayViewController : UIViewController {
UILabel *lblCurrentLocation;
}
#define SCREEN ([[UIScreen mainScreen] bounds])
@end
.m file
#import "TodayViewController.h"
@interface TodayViewController () <NCWidgetProviding>
@end
@implementation TodayViewController
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
lblCurrentLocation = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
lblCurrentLocation.text = @"Current Location: Unknown";
[self.view addSubview:lblCurrentLocation];
NSLog(@"Set up");
}
- (void)widgetPerformUpdateWithCompletionHandler:(void (^) (NCUpdateResult))completionHandler {
// Perform any setup necessary in order to update the view.
// If an error is encountered, use NCUpdateResultFailed
// If there's no update required, use NCUpdateResultNoData
// If there's an update, use NCUpdateResultNewData
completionHandler(NCUpdateResultNewData);
}
@end