【发布时间】:2013-09-24 00:22:45
【问题描述】:
我正在使用情节提要为 iPad 开发一个项目。 我正在尝试使用来自 plist 的数据填充我的 UITableView。 Plist 有一个 NSDictionary,它又包含 9 个数组,每个数组包含三个元素(一个数字和两个字符串)。我想从每个数组(它是一个字符串)中取出第二个元素 [1] 并用这些字符串填充表。
来自头文件;
@interface EonOrderOfPrinciple : UIViewController
<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *formManeuvers;
@property (nonatomic, strong) NSDictionary *Wild;
@property (nonatomic, strong) NSArray *Smash;
@property (nonatomic, strong) NSArray *CloseCombat;
@property (nonatomic, strong) NSArray *HeadButt;
@property (nonatomic, strong) NSArray *Pummel;
@property (nonatomic, strong) NSArray *Obstacle;
@property (nonatomic, strong) NSArray *Confusion;
@property (nonatomic, strong) NSArray *ImpWeap;
@property (nonatomic, strong) NSArray *Rage;
@property (nonatomic, strong) NSArray *WildStorm;
从实施开始;
NSString *aFile = [[NSBundle mainBundle]
pathForResource:@"Wild" ofType:@"plist"];
Wild = [[NSDictionary alloc] initWithContentsOfFile:aFile];
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"cell"];
NSString *currentManeuverName;
currentManeuverName = [Smash objectAtIndex:1];
[[cell textLabel] setText:currentManeuverName];
return cell;
}
@end
我意识到我现在只给它一个细胞。我想一旦我得到一个工作,我就可以尝试让其余的人填充。现在我连那个都买不到。
没有任何教程,也没有我找到的帮助,解释了如何使用这样的嵌套数据。我尝试使用我发现的各种版本的东西,但没有任何效果。 在转向 Core Data 之前,我想学习如何使用 plist。非常简单的 plist 我已经很好地工作了,似乎是这个嵌套的业务让我绊倒了。
* 10 月 29 日更新 ...我现在已删除 plist *
所以。如何使用嵌套字典 plist 正确访问信息并填充表格。同样,这是使用嵌套字典。这是我不知道该怎么做的,这是我正在努力学习的。
【问题讨论】:
-
我为 Wild and Smash 做了@synthesize
-
你能用plist内容更新问题吗?
-
与您的问题无关,但是为什么您在使用
dequeueReusableCellWithIdentifier重用单元格后分配另一个单元格? -
currentManeuverName为零吗? -
感觉您的问题是在寻求代码解决方案,而您最好深入研究 plist 并在需要时提出更具体的问题。有多种方法可以满足您的要求(例如使用表格部分或将数组复制到表格数组属性等)
标签: objective-c arrays ipad uitableview plist