WebListViewController
からにプッシュしようとしているWebPageViewController
ので、セルが押されると にプッシュされ、それにUIWebView
関連付けられた Web 記事が表示されます。しかし、私はそれを機能させることができません-
WebListViewController.m
#import "WebListViewController.h"
#import "Feed.h"
@interface WebListViewController ()
@property (strong, nonatomic) NSArray *headlinesArray;
@end
@implementation WebListViewController
@synthesize tableView = _tableView;
@synthesize headlinesArray;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"standardCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Feed *feedLocal = [headlinesArray objectAtIndex:indexPath.row];
NSString *headlineText = [NSString stringWithFormat:@"%@", feedLocal.headline];
cell.textLabel.text = headlineText;
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"webpage"]) {
UITableViewCell *cell = (UITableViewCell*)sender;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
WebPageViewController *wpvc = (WebPageViewController *) [segue destinationViewController];
wpvc.buttonNumber = _buttonNumber;
Feed *feedLocal = [headlinesArray objectAtIndex:indexPath.row];
NSString *stringWeb = [NSString stringWithFormat:@"%@", feedLocal.links.web.href];
wpvc.stringWeb = stringWeb;
}
}
WebPageViewController.h
@interface WebPageViewController : UIViewController <UIWebViewDelegate>
@property (nonatomic) int buttonNumber;
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@property (strong, nonatomic) NSString *stringWeb;
@end
WebPageViewController.m
#import "WebPageViewController.h"
#import "Feed.h"
@interface WebPageViewController ()
@property (strong, nonatomic) NSArray *headlinesArray;
@end
@implementation WebPageViewController
@synthesize stringWeb;
@synthesize headlinesArray;
-(void)viewWillAppear:(BOOL)animated {
NSURL *url = [NSURL URLWithString:stringWeb];
[self.webView loadRequest:[NSURLRequest requestWithURL:url]];
}
-(void)viewWillDisappear:(BOOL)animated {
[self.webView stopLoading];
}
JSON レスポンス
{
"timestamp": "2013-05-04T16:38:48Z",
"feed": [{
"headline": "Text of headline",
"links": {
"web": {
"href": "http://website.com/article"
},
<UIWebViewDelegate>
たぶんそれが起こっていると思ったので、今日その部分を追加しましたが、それでも機能しませんでした. cellForRowAtIndexPath
コンソールに正しいデータがすべて表示されているので、正しいことがわかります。プログラムを実行すると、WebPageViewController
選択したセルが強調表示されたままになります。問題が何であるか、prepareForSegue
または追加する必要がdidSelectRowAtIndexPath
あるか、何か違うものかどうかわかりません。
(API から JSON データを取得しています。)
アドバイスは非常に役に立ちます。必要なコードを追加します。ありがとう!