我需要帮助如何将我的SQLite数据库连接到我的watchkit app扩展。我不太熟悉将sqlite与单元格行一起使用。任何简单的示例代码都将是一个很好的帮助谢谢。下面是我使用的示例数组。
#import "ICBQuoteSource.h"
@implementation ICBQuoteSource
+(NSArray *)quoteDictionary {
NSMutableArray *quotes = [NSMutableArray new];
[quotes addObject:@{@"characterImage": @"moss", @"characterName": @"Moss", @"quote": @"I came here to drink milk and kick ass... and I've just finished my milk."}];
[quotes addObject:@{@"characterImage": @"roy", @"characterName": @"Roy", @"quote": @"Hello, IT, have you tried turning it off and on again?"}];
[quotes addObject:@{@"characterImage": @"moss", @"characterName": @"Moss", @"quote": @"Did you see that ludicrous display last night?"}];
[quotes addObject:@{@"characterImage": @"denholm", @"characterName": @"Denholm", @"quote": @"That's the sort of place this is, Jen. A lot of sexy people not doing much work and having affairs."}];
[quotes addObject:@{@"characterImage": @"moss", @"characterName": @"Moss", @"quote": @"This Jen is the Internet"}];
return [NSArray arrayWithArray:quotes];
}
@end
#import "InterfaceController.h"
#import "ICBQuoteSource.h"
#import "rowController.h"
@interface InterfaceController()
@property (nonatomic, strong) NSArray *quotes;
@end
@implementation InterfaceController
- (void)awakeWithContext:(id)context
{
[super awakeWithContext:context];
// Get quotes
self.quotes = [ICBQuoteSource quoteDictionary];
// Set number of table Row
[self.table setNumberOfRows:self.quotes.count withRowType:@"Row Controller"];
// Set row properties
for (NSDictionary *quote in self.quotes) {
rowController *quoteRow = [self.table rowControllerAtIndex:[self.quotes indexOfObject:quote]];
[quoteRow.englishTxtLabel setText:quote[@"characterName"]];
[quoteRow.translationTxtLabel setText:quote[@"quote"]];
}
}
- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
[super willActivate];
}
- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
[super didDeactivate];
}
@end
答案 0 :(得分:0)
你还没有真正陈述问题是什么......所以让我试着猜一猜。我假设你的表中的行没有正确显示。我建议尝试将行设置逻辑移到willActivate
。这是我在Xcode 6.2b5中使用表时发现的。您无法在awakeWithContext(:)
中获得相应的行为。
希望这有助于引导您朝着正确的方向前进。如果这不是您遇到的实际问题,请编辑您的问题,我会相应地修改我的答案。