2012-01-17 3 views
0

こんにちは、私はiPadアプリで作業していると私はいくつかのアドバイスが必要です。配列に格納されたURLを使用して、アプリからSafariにウェブサイトを開く方法は?

私はユーザーのオンライン情報を格納する配列を持ち、データの1つはURLです。 情報の一覧がマスター詳細テーブルビューに表示され、選択されると、その詳細情報がすべて表示されます。各情報の1つはURLです。私はSafariに私を連れて来て、そのウェブページを表示するボタンをクリックすることで、そのURLに行くことができるようにしたい。以下

は問題です:

-(IBAction)loginClicked:(id)sender{ 
NSLog(@"loginClicked"); 

//--What should i replace indexPath.row with so that it will point to the current selected row? 
loginObj = [appDelegate.loginArray objectAtIndex:indexPath.row]; 

//--if the above indexPath.row is replaced with an integer, the NSLog is able to print out the correct URL of that row 
NSLog(@"URL = %@", loginObj.loginURL); 

//--then when i insert loginObj.loginURL, it gives me error "too many arguments method to call, expected 1, have 2" but when i insert a proper URL @"http://www.google.com" it has no problem opening it up. 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"%@", loginObj.loginURL]]; 

} 

loginURLは私のクラスにNSStringのように宣言されています。

私はあなたのdidSelectRow方法では、

int theCurrentSelectedRow; 

をお使いのインタフェース・ファイル内の以下のような整数を宣言しSDK4.2 iOS5を、ストーリーボード

答えて

0

とiPadのマスター・ディテール・ビュー・テンプレートを使用しています

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
    theCurrentSelectedRow = indexPath.row; 
} 

次のようにメソッドを変更してください。

-(IBAction)loginClicked:(id)sender{ 
NSLog(@"loginClicked"); 

loginObj = [appDelegate.loginArray objectAtIndex:theCurrentSelectedRow]; 

NSLog(@"URL = %@", loginObj.loginURL); 

[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"%@", loginObj.loginURL]]; 

} 

アイデアは、現在選択されている行インデックスをグローバル変数に格納し、アクセスするためにメソッド内で使用することです。

0

+[NSURL URLWithString:]は可変引数をサポートしていません。あなたは、コードのこのビットが間違ってであることを、少なくともコンパイラの警告を受信する必要があります。

代わり
[NSURL URLWithString: @"%@", loginObj.loginURL] 

、URLを構築するために、単に:

[NSURL URLWithString:loginObj.loginURL] 

さらに良いことに、あなたのモデルクラスを更新します直接NSURLに対処する。

関連する問題