-4

我有一个乐队应用程序,该应用程序需要在其上安装乐器音阶。为此,我试图拥有一个带有比例名称和描述的 PList 文件。我已经研究过,我能找到的只是传递图像,而不是 URL。我已经完成了plist。这是其中的一部分:

/Users/grandslam700/Desktop/Scr​​een Shot 2013-04-01 at 7.05.50 PM.png 而且我还有一个表格视图,用于获取 Plist 文件的名称和比例部分。

在此处输入图像描述

我不知道该怎么做是,如何深入到详细视图控制器,然后将单击的表视图单元格的 URL 加载到 UI Webview 中,这是主表的 .m 中的代码看法:

#import "TableViewController.h"
#import "DetailView.h"
@interface TableViewController ()
@end

@implementation TableViewController
@synthesize content = _content;

-(NSArray *)content
{
    if (!_content) {
        _content = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Scales" ofType:@"plist"]];
    }
return _content;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Make sure your segue name in storyboard is the same as this line
    if ([[segue identifier] isEqualToString:@"Detail"])
    {
        // Get reference to the destination view controller
    }
}

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

- (void)viewDidLoad
{
    [super viewDidLoad];

// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

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

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [self.content count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    cell.textLabel.text = [[self.content objectAtIndex:indexPath.row] valueForKey:@"Name"];
    cell.detailTextLabel.text = [[self.content objectAtIndex:indexPath.row] valueForKey:@"Scale"];

return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
 // ...
 // Pass the selected object to the new view controller.
 [self.navigationController pushViewController:detailViewController animated:YES];
  */
}

@end

`如果有人知道如何做到这一点,请帮助我?

4

1 回答 1

1
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
 detailViewController.webLink = [[self.content objectAtIndex:indexPath.row] valueForKey:@"URL"];//webLink is NSStringProperty in DetailViewController.h
 [self.navigationController pushViewController:detailViewController animated:YES];
}

在 DetailViewController 的 viewDidLoad 中加载 UIWebView 使用 XIB

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.webLink]]];
}

关于如何推送到 WebViewController,参考示例代码: https ://github.com/lequysang/github_zip/blob/master/TestTapOnWeb.zip

带故事板。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
     NSString *webLink = [[self.content objectAtIndex:indexPath.row] valueForKey:@"URL"];//webLink is NSStringProperty in DetailViewController.h
        [[segue destinationViewController] setWebLink:webLink];
    }
}
于 2013-04-02T01:07:59.117 回答