【发布时间】:2015-03-12 21:10:12
【问题描述】:
我最近在我的应用程序中添加了一个小部件,或者尝试过添加。当我运行它时,小部件显示在通知中心,但它似乎已折叠。我已经确认没有使用 NSLog 调用 viewDidLoad。任何想法为什么它不加载?谢谢。
编辑:似乎问题是不会添加标签我必须在界面构建器中创建所有内容。
.h 文件
#import <UIKit/UIKit.h>
#import <NotificationCenter/NotificationCenter.h>
@interface TodayViewController : UIViewController {
UILabel *lblCurrentLocation;
}
#define SCREEN ([[UIScreen mainScreen] bounds])
@end
.m 文件
#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
【问题讨论】:
-
请出示您的代码,以便我们检查。这描述得不好,而且太模糊了。
-
@bolencki13 你有什么解决办法吗?我面临着类似的问题!
-
我不得不使用界面生成器。我无法以编程方式添加标签或任何东西
标签: ios objective-c ios8 viewdidload ios8-today-widget