使用plist和tableview在详细视图的webview中加载html文件时遇到问题

时间:2013-08-16 01:58:44

标签: ios uitableview webview plist detailsview

  • 我有a1.html,a2.html,b1.html,b2.html作为本地资源 应用
  • 我无法使用plist加载这些html文件 tableview into detailview的webview

PLIST

topics.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"     "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>HN</key>
<array>
    <dict>
        <key>Name</key>
        <string>Boston</string>
        <key>File</key>
        <string>a1</string>
    </dict>
    <dict>
        <key>Name</key>
        <string>Massachussets</string>
        <key>File</key>
        <string>a2</string>
    </dict>
</array>
<key>LEA</key>
<array>
    <dict>
        <key>Name</key>
        <string>Birmingham</string>
        <key>File</key>
        <string>b1</string>
    </dict>
    <dict>
        <key>Name</key>
        <string>Alabama</string>
        <key>File</key>
        <string>b2</string>
    </dict>
</array>

泰伯维

TopicsTableViewController.m

#import "TopicsTableViewController.h"
#import "TopicDisplayViewController.h"


#define HNSection 0
#define LEASection 1

#define numberOfSections 2

@interface TopicsTableViewController ()
@property (nonatomic, retain) NSMutableDictionary *topicslist;

@end

@implementation TopicsTableViewController

@synthesize topicslist;

- (id)initWithStyle:(UITableViewStyle)style
  {
self = [super initWithStyle:style];
if (self) {
    // CUSTOMIZE INITIATION
}
return self;
}

- (void)viewDidLoad {

[super viewDidLoad];

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"topics" ofType:@"plist"];
TopicsDict = [[NSDictionary alloc] initWithContentsOfFile:plistPath];


self.HNArray = TopicsDict[@"HN"];
self.LEAArray= TopicsDict[@"LEA"];      
}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:  (NSInteger)section {

 switch (section){


 case HNSection:
     return @"NorthEast";
  break;
 case LEASection:
     return @"South";
 break;

 default:
     return 0;
 }   
 }

  // Customize the number of rows in the table view.

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section    {

switch (section)
{
    case HNSection:
        return [self.HNArray count];
        break;
    case LEASection:
        return [self.LEAArray count];
        break;
    default:
        return 0;

    }
  }
 // Customize the appearance of table view cells.
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

   switch (indexPath.section)
    {
    case HNSection:

     cell.textLabel.text = self.HNArray[indexPath.row][@"Name"];
        break;
    case LEASection:
         cell.textLabel.text = self.LEAArray[indexPath.row][@"Name"];
        break;
    default:
        return 0;
}
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
return cell;



}

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath  *)indexPath
{

    TopicDisplayViewController*destinationController ;
    NSString*file;

    switch (indexPath.section)
    {       
        case HNSection:
            file = [[NSString alloc] initWithFormat:@"%@", self.HNArray[indexPath.row][@"File"]];
            destinationController.htmlfile  =  self.HNArray[indexPath.row][@"File"];

            break;
        case LEASection:
              file = [[NSString alloc] initWithFormat:@"%@", self.LEAArray[indexPath.row][@"File"]];
            destinationController.htmlfile  =  self.LEAArray[indexPath.row][@"File"];
            break;

    }

}

 - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:   (NSIndexPath *)indexPath {
[self tableView:tableView didSelectRowAtIndexPath:indexPath];
 }

 @end

DEATAILVIEW

TopicDisplayViewController.h

#import <UIKit/UIKit.h>
@interface TopicDisplayViewController : UIViewController {
    IBOutlet UIWebView*topicview;
    NSString*htmlfile;
}
 @property (retain) NSString*htmlfile;
 @property (nonatomic) UIWebView*topicview;
 @end

TopicDisplayViewController.m

#import "TopicDisplayViewController.h"
@interface TopicDisplayViewController ()

@end

@implementation TopicDisplayViewController

 @synthesize htmlfile;


 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
NSString *bundle = [[NSBundle mainBundle] bundlePath];
NSString *webPath = [bundle stringByAppendingPathComponent:htmlfile];
[topicview loadRequest:[NSURLRequest requestWithURL:
                      [NSURL fileURLWithPath:webPath]]];

 }

 @end

0 个答案:

没有答案