このサイトは初めてですが、過去数時間、非常に単純でなければならないことがわかっていることを修正しようとした後、頭が完全に死んでいます.
ショートストーリー:
- UINavigationController を持つ UIViewController があります
- UIViewController (tableView) は、RSS フィードのストーリーを解析して表示する UITableView です。
- UINavigationController によってプッシュされる UIWebView を持つ 2 番目の UIViewController (newsWebView) があり、ユーザーが tableView の行をクリックすると各ストーリーが表示されます。
- ユーザーが UIWebView の操作を完了すると、最初のビューである tableView に戻されます
2番目のコントローラーで各行のURLをwebViewにプッシュすることを除いて、すべてが機能しています。ビューをプッシュしますが、URL が 2 番目のコントローラーに送信されないため、webView は空白です。コード内の NSLog は、URL も正常に作成されていることを示しています。では、newsWebView で URL を処理するにはどうすればよいでしょうか?
tableView.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @"link"];
// clean up the link - get rid of spaces, returns, and tabs...
storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:@"\n" withString:@""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"storyLink: %@", storyLink);
if (storyLink != nil && ![storyLink isEqualToString:@""]) {
// Wrapping the troublesome call with logs so you should be able to see if this is the line that is killing your app
NSLog(@"about to create url");
NSURL *url = [NSURL URLWithString:storyLink];
NSLog(@"creating url was successful");
//URL Request Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView
newsWebView *detailViewController = [[newsWebView alloc] initWithNibName:@"newsDetailWebView" bundle:nil];
//detailViewController.item = [[stories objectAtIndex: storyIndex] objectForKey: @"link"];
[self.navigationController pushViewController:detailViewController animated:YES];
//[detailViewController loadRequest:requestObj];
[detailViewController release];
}
}
では、newsWebView.m の viewDidLoad に何を追加する必要があるのでしょうか? または、さらに言えば、私の tableView の didSelectRowAtIndexPath の何が問題なのですか?
newsWebView.m
- (void)viewDidLoad {
}
本当にありがとう。アドビルを服用する必要があります。