我試圖從WebListViewController
推到WebPageViewController
,所以當一個單元格被按下時,它會推送到一個UIWebView
來顯示與之相關的網頁文章。但我就是不能讓它working-UITableView prepareForSegue不推送到UIWebView
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數據。)
任何意見將是有益的超級,我會添加所需的任何代碼,謝謝!
感謝您的迴應!是的,standardCell是我在故事板中定義爲原型的單元格。即使我從TableView推送 - > WebView(您的圖像是TableView - > TableView),這是否會處理您的建議工作? – Realinstomp 2013-05-04 23:13:47
是的,它適用於所有視圖控制器,無論類型如何。 – TheQ 2013-05-04 23:28:55
你是最棒的。完美工作! – Realinstomp 2013-05-04 23:46:40