1

我正在尝试更改 Sam 在 24 小时内自学 iOS 的教程之一。在这个例子中,一个 tableview 加载了一个 NSMutableArray,它定义了各种外部 URL。如何修改这段代码以调用 html 文件(捆绑)而不是外部 URL?提前致谢。代码是这样的:

- (void)createFlowerData {

NSMutableArray *redFlowers;
NSMutableArray *blueFlowers;

_flowerSections=@[@"Red Flowers",@"Blue Flowers"];

redFlowers=[[NSMutableArray alloc] init];
blueFlowers=[[NSMutableArray alloc] init];

[redFlowers addObject:@{@"name":@"Poppy",
@"picture":@"Poppy.png",
@"url":@"http://en.wikipedia.org/wiki/Poppy"}];
[redFlowers addObject:@{@"name":@"Tulip",
@"picture":@"Tulip.png",
@"url":@"http://en.wikipedia.org/wiki/Tulip"}];
[redFlowers addObject:@{@"name":@"Gerbera",
@"picture":@"Gerbera.png",
@"url":@"http://en.wikipedia.org/wiki/Gerbera"}];
[redFlowers addObject:@{@"name":@"Peony",
@"picture":@"Peony.png",
@"url":@"http://en.wikipedia.org/wiki/Peony"}];
[redFlowers addObject:@{@"name":@"Rose",
@"picture":@"Rose.png",
@"url":@"http://en.wikipedia.org/wiki/Rose"}];
[redFlowers addObject:@{@"name":@"Hollyhock",
@"picture":@"Hollyhock.png",
@"url":@"http://en.wikipedia.org/wiki/Hollyhock"}];
[redFlowers addObject:@{@"name":@"Straw Flower",
@"picture":@"Strawflower.png",
@"url":@"http://en.wikipedia.org/wiki/Peony"}];
[blueFlowers addObject:@{@"name":@"Hyacinth",
@"picture":@"Hyacinth.png",
@"url":@"http://en.m.wikipedia.org/wiki/Hyacinth_(flower)"}];
[blueFlowers addObject:@{@"name":@"Hydrangea",
@"picture":@"Hydrangea.png",
@"url":@"http://en.m.wikipedia.org/wiki/Hydrangea"}];
[blueFlowers addObject:@{@"name":@"Sea Holly",
@"picture":@"Sea Holly.png",
@"url":@"http://en.wikipedia.org/wiki/Sea_holly"}];
[blueFlowers addObject:@{@"name":@"Grape Hyacinth",
@"picture":@"Grape Hyacinth.png",
@"url":@"http://en.wikipedia.org/wiki/Grape_hyacinth"}];
[blueFlowers addObject:@{@"name":@"Phlox",
@"picture":@"Phlox.png",
@"url":@"http://en.wikipedia.org/wiki/Phlox"}];
[blueFlowers addObject:@{@"name":@"Pin Cushion Flower",
@"picture":@"Pincushion flower.png",
@"url":@"http://en.wikipedia.org/wiki/Scabious"}];
[blueFlowers addObject:@{@"name":@"Iris",
@"picture":@"Iris.png",
@"url":@"http://en.wikipedia.org/wiki/Iris_(plant)"}];

_flowerData=@[redFlowers,blueFlowers];

}

我尝试了以下方法:

NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"html"];

然后改变:

[redFlowers addObject:@{@"name":@"Poppy",
@"picture":@"Poppy.png",
@"url":htmlpath}];

当我连续点击时,我得到新视图被推入,但我的 html 文件没有显示。查看详细视图代码:

@interface DetailViewController ()
- (void)configureView;
@end

@implementation DetailViewController

#pragma mark - Managing the detail item

- (void)setDetailItem:(id)newDetailItem
{
    if (_detailItem != newDetailItem) {
        _detailItem = newDetailItem;

        // Update the view.
        [self configureView];
    }
}

- (void)configureView
{
    // Update the user interface for the detail item.

    if (self.detailItem) {
        NSURL *detailURL;
        detailURL=[[NSURL alloc] initWithString:self.detailItem[@"url"]];
        [self.detailWebView loadRequest:[NSURLRequest requestWithURL:detailURL]];
        self.navigationItem.title = self.detailItem[@"name"];
        self.detailDescriptionLabel.hidden=YES;
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self configureView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

我错过了什么?看起来它应该工作!

4

0 回答 0