3
我刚开始学习如何在iOS8上创建今日视图窗口小部件。我为扩展创建了一个新的目标。下一步,我删除了默认viewcontroller
和类,并创建了一个新的UITableViewController
,它是相应的方法。我实现了以下内容:今天的iOS8视图窗口小部件不显示UITableViewController
#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;
}
我也改变了表的大小来freeform
它的高度设置为300像素。但我没有得到任何回报。小部件变空了。
非常感谢汤姆!非常精确和有用的答案。 – user3687 2014-11-25 18:38:55