开发者

Load specific URL after pushing from UITableView

I create UITableView and I have 3 cells , so each cell should push to DetailViewController to load specific URL . On detailViewController I have UIWebView that load url after user select a cell of tableView , But I don't know how can I do this things ! . Here is my code

.h:

    #import "webController.h"

@class webController;
@interface RootViewController : UITableViewController <UITableViewDelegate , UITableViewDataSource> {

    NSArray *list;
    webController *webcontroller;
}

@property (nonatomic , retain) IBOutlet NSArray *list;

@end

.m:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


if (!webcontroller) {
    webcontroller = [[webController alloc] initWithNibName:nil bundle:nil];
    webcontroller.navigationItem.title = [list objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:webcontroller animated:YES];


}else {
    webcontroller.navigationItem.title=[list objectAtIndex:indexPa开发者_JAVA百科th.row];
    [self.navigationController pushViewController:webcontroller animated:YES];  


}


}


I would like to what iHS said:

The best way (in my opinion) would be to have two NSArray's. One to display the name (google, apple, yahoo) and then one to store the specific URL.

So you could do something like this

in .h:

NSArray *urlArray;

and then in the .m: (modified iHS's code)

if (!webcontroller) {
     webcontroller = [[webController alloc] initWithNibName:nil bundle:nil];
}
 webcontroller.navigationItem.title=[list objectAtIndex:indexPath.row];
webcontroller.strUrl = [urlArray objectAtIndex:indexPath.row]; //Load the url at the specific index in "urlArray"
[self.navigationController pushViewController:webcontroller animated:YES];

Post any questions below ;)


You can achieve this by various methods. The simpler and best would be to create a property in your webController class

@property(nonatomic, retain) NSString *strUrl

and then synthesize it by using

@synthesize strUrl in your webController.m

Now in

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


if (!webcontroller) {
    webcontroller = [[webController alloc] initWithNibName:nil bundle:nil];
}

 webcontroller.navigationItem.title=[list objectAtIndex:indexPath.row];
 webcontroller.strUrl = [list objectAtIndex:indexPath.row];
 [self.navigationController pushViewController:webcontroller animated:YES];  


 }

Then use this strUrl to load the page in webview. I hope it helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜