ios - UITableView prepareForSegue not pushing to UIWebView -
i'm trying push weblistviewcontroller
webpageviewcontroller
, when cell pressed push uiwebview
show web article associated it. can't working-
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 response
{ "timestamp": "2013-05-04t16:38:48z", "feed": [{ "headline": "text of headline", "links": { "web": { "href": "http://website.com/article" },
i added <uiwebviewdelegate>
part today because thought maybe thats happening, still wasn't working. know cellforrowatindexpath
correct because see of correct data in console. when run program seems never webpageviewcontroller
, cell selected stays highlighted. can't figure out problem is, if prepareforsegue
or needing add didselectrowatindexpath
or different.
(i'm pulling json data api.)
any advice super helpful, , i'll add code needed, thanks!
i'm guessing standardcell cell have defined prototype cell in storyboard? if so, make sure right click cell , drag "selection"-property view controller want cell push onto navigation controller.
also, make sure first view embedded in navigation controller. if it's not, select in storyboard, , go editor-menu, select "embed in", , "navigation controller".
Comments
Post a Comment