我很困惑,爲什麼我的PList數據未顯示在表格視圖單元格中。應用程序運行,但單元格是空白的。請你能幫助我知道我哪裏出錯了。謝謝。未在UITableView中顯示Plist數據
片段的plist的(healthlist.plist)
<plist version="1.0">
<dict>
<key>Health</key>
<array>
<dict>
<key>title</key>
<string>Allergies</string>
<key>info</key>
<string>Allergies are caused by an overactive immune system. The immune system is designed to protect however when it mistakes non-harmful environmental substances (allergens) as threats then an allergic reation will occur</string>
<key>symptoms</key>
<string>Itching, licking, chewing the skin or scratching with their feet. Common areas are face, ears, belly, feet and armpit region.</string>
<key>common</key>
<string>Environmental allergens include dust mites, fleas, mold and pollens. Food allergies or food intolerance to certain ingredients such as, beef, soy, wheat, fish, rice and chicken.</string>
<key>cure</key>
<string>Treatment options for allergies: corticosteroids, antihistamines, allergy vaccine, shampoos and cyclosporine. Always seek a Vets advice. </string>
<key>image</key>
<string>allergy.jpg</string>
HealthTableViewController.h片段
@interface HeathTableViewController : UITableViewController <UITableViewDelegate, NSFetchedResultsControllerDelegate>
@property (nonatomic, strong) NSArray *Health;
@property (nonatomic, strong) NSArray *title;
@property (nonatomic, strong) NSArray *info;
@property (nonatomic, strong) NSArray *symptoms;
@property (nonatomic, strong) NSArray *common;
@property (nonatomic, strong) NSArray *cure;
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
HealthViewController.m片斷
- (void)viewDidLoad
{
[email protected]"Health";
NSString *HealthFile = [[NSBundle mainBundle] pathForResource:@"healthlist" ofType:@"plist"];
NSDictionary *HealthDict = [[NSDictionary alloc]
initWithContentsOfFile:HealthFile];
Health = [HealthDict objectForKey:@"health"];
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [Health count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
NSDictionary *health = [Health objectAtIndex:indexPath.row];
NSString *nameOfTitle = [health objectForKey:@"title"];
cell.textLabel.text = nameOfTitle;
return cell;
}
提示:使用一組自定義對象而不是許多通用對象數組。 – trojanfoe
在委託方法中加入斷點並查看它們是否被調用。從那裏打印出來的數據通過NSLog或調試器控制檯和功能 –