ios - Trouble loading html file in webview of detailview using plist and tableviw -
- i have a1.html, a2.html, b1.html, b2.html local resources within app.
- i having trouble loading these html files using plist , tableview detailview's 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>
tableview
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 number of rows in 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 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
Comments
Post a Comment