URL从Plist到详细信息视图控制器的Web视图

时间:2013-04-02 00:44:17

标签: ios objective-c xcode url plist

我有一个乐队应用程序,应用程序需要有仪器秤。为此,我试图获得一个带有比例名称和描述的PList文件。我已经研究过,我能找到的只是传递图像,而不是URL。我完成了plist。以下是其中的一部分:

/Users/grandslam700/Desktop/Screen Shot 2013-04-01 at 7.05.50 PM.png 我还有一个表视图获取Plist文件的名称和比例部分。

enter image description here

我无法弄清楚该怎么做,我如何深入查看详细信息视图控制器,然后将点击的表视图单元格的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

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

1 个答案:

答案 0 :(得分: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];
    }
}