-4

アプリに楽器のスケールが必要なバンドアプリケーションがあります。これを行うために、スケールの名前と説明を含む PList ファイルを作成しようとしています。私が調査したところ、URLではなく画像を渡すことだけが見つかりました。plistができました。その一部を次に示します。

/Users/grandslam700/Desktop/スクリーンショット 2013-04-01 at 7.05.50 PM.png また、Plist ファイルの名前とスケール部分を取得するテーブル ビューもあります。

ここに画像の説明を入力

どうすればよいかわかりません。詳細ビュー コントローラーにドリルダウンして、クリックしたテーブル ビュー セルの URL を UI Web ビューにロードする方法は次のとおりです。メイン テーブルの .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 に答える