Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-23-2011, 06:54 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Location: Australia
Posts: 10
ellawson is on a distinguished road
Question Pushing separate WebView URLs for second-level TableView items

Hi all,

OK. I have an app in development that has a list of items in a TableView. When you select a row it slides to another list of TableView items, which when you select an item will open a WebView URL.

Here's my issue: I have the top-level TableView list in. All the rows there go to their respective second-level TableView lists. But I'm not sure how to go about getting each of the second-level TableView items to go to their own WebView URLs - at the moment ALL the second level list items go to the same set of WebViews as the first set of top-level items.

e.g. (Level 1)Facilities > (Level2)Accommodation > (WebView)URL address 1
(Level 2)Gym > (WebView)URL address 2
(Level 2)Post Office > (WebView)URL address 3
(Level 1)Library > (Level2)Services > (WebView)URL address 1 (same as above)
(Level 2)How to > (WebView)URL address 2 (same as above)
(Level 2)Search > (WebView)URL address 3 (same as above)
etc...

This what I have at the moment:

Code:
//RootViewControler.m

...

- (void)viewDidLoad {
    [super viewDidLoad];
    self.authorList = [[NSArray alloc] initWithObjects:@"Student Facilities", 
					   @"Library", @"Student Support", @"External Study", @"Resources", nil];
    self.title = @"Students";

...

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
	if (0 == indexPath.row)
	{       
		self.booksController.title = @"Student Facilities";
	} else if (1 == indexPath.row)
	{       
		self.booksController.title = @"Library";
	} else if (2 == indexPath.row)
	{       
		self.booksController.title = @"Student Support";
	} else if (3 == indexPath.row)
	{       
		self.booksController.title = @"External Study";
	} else {
		self.booksController.title = @"Resources";
	}
	
	[self.navigationController pushViewController:self.booksController animated:YES];
}

...


//
//LevelTwoViewController.m

...

- (void)viewWillAppear:(BOOL)animated {
	if ([self.title isEqualToString:@"Student Facilities"]) {
		books = [[NSArray alloc ] initWithObjects:@"Student accommodation", @"Gym", @"Post Office", @"Bookshop", nil];
	} else if ([self.title isEqualToString:@"Library"]) {
		books = [[NSArray alloc ] initWithObjects:@"Library services", @"Library how to", @"Library search", @"Library website", nil];
	} else if ([self.title isEqualToString:@"Student Support"]) {
		books = [[NSArray alloc ] initWithObjects:@"Online", @"Dates", @"Enrolments", @"Exams", @"Timetables", @"Accounts", nil];
	} else if ([self.title isEqualToString:@"External Study"]) {
		books = [[NSArray alloc ] initWithObjects:@"External assignments", @"External exams", @"Open Universities scheme", @"Dispatch", nil];
	} else {
		books = [[NSArray alloc ] initWithObjects:@"Studying online", @"Learnline FAQs", @"Learnline tutorials", @"Learnline manuals", nil];
	}
	
	[super viewWillAppear:animated];
	[self.tableView reloadData];
}

...

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   
	UIViewController *webViewController = [[[UIViewController alloc] init] autorelease];
	
	UIWebView *uiWebView = [[[UIWebView alloc] initWithFrame: CGRectMake(0,0,320,480)] autorelease];
	if (0 == indexPath.row)
	{       
		[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];
	} else if (1 == indexPath.row)
	{       
			[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.yahoo.com"]]];
	} else if (2 == indexPath.row)
	{       
		[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.hotmail.com"]]];
	} else {
			[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://ninemsn.com.au"]]];
	}
	uiWebView.scalesPageToFit = YES; // uiWebView - object of UiWebview

	[webViewController.view addSubview: uiWebView];
	
	[self.navigationController pushViewController:webViewController animated:YES];
	
}
Being a newbie to the whole programming and Xcode thing, just let me know any other code you need to see and I'll gladly post it.

Any help is much appreciated, thanks.
ellawson is offline   Reply With Quote
Old 03-23-2011, 08:32 PM   #2 (permalink)
Registered Member
 
Join Date: Mar 2011
Location: Australia
Posts: 10
ellawson is on a distinguished road
Default

Funnily enough, I was able to help myself

For any other newbies out there who come across this later on, it's pretty simple - within the didSelectRowAtIndexPath method, put an if statement (self.title isEqualToString @"Top Level Item Name") for each top-level item, then nest another if statement (indexPath.row == i) within it and include each uiWebView URL there.

Works like a charm!
ellawson is offline   Reply With Quote
Old 03-24-2011, 01:18 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 1
jelmer1993 is on a distinguished road
Default Can you help me

Quote:
Originally Posted by ellawson View Post
Funnily enough, I was able to help myself

For any other newbies out there who come across this later on, it's pretty simple - within the didSelectRowAtIndexPath method, put an if statement (self.title isEqualToString @"Top Level Item Name") for each top-level item, then nest another if statement (indexPath.row == i) within it and include each uiWebView URL there.

Works like a charm!
I have the same problem, I have a tableview and if you click at one item, then you go to a detailview with a unique URL for webView. I think it's the same idea as yours. Could you help me, or send your solution in .xcodeproject?
jelmer1993 is offline   Reply With Quote
Old 03-24-2011, 06:08 PM   #4 (permalink)
Registered Member
 
Join Date: Mar 2011
Location: Australia
Posts: 10
ellawson is on a distinguished road
Lightbulb

Quote:
Originally Posted by jelmer1993 View Post
I have the same problem, I have a tableview and if you click at one item, then you go to a detailview with a unique URL for webView. I think it's the same idea as yours. Could you help me, or send your solution in .xcodeproject?
This is assuming your table view has been constructed using NSArray or similar with a self.title attribute (e.g. self.title isEqualToString:@"Your Row Name").

So I'm guessing in your detailview you would find your didSelectRowAtIndexPath method and put something like this:

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

	UIViewController *webViewController = [[[UIViewController alloc] init] autorelease];
	
	UIWebView *uiWebView = [[[UIWebView alloc] initWithFrame: CGRectMake(0,0,320,480)] autorelease];
	if ([self.title isEqualToString:@"Row Name 1"]){ //if the tableview row with this title is selected
if (indexPath.row == 0) { //then the first subrow should open this webview URL
			[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];
		} else if (indexPath.row == 1) { //the second subrow
			[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.amazon.com"]]];
		}  else { //any other subrows
		[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.yahoo.com"]]];
		}
	} else if ([self.title isEqualToString:@"Row 2 Name"]){ //if the tableview row with this title is selected
		if (indexPath.row == 0) { //then the first subrow will open this webview URL
			[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.coles.com.au"]]];
		} else { //any other subrows will open this one
			[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.cdu.edu.au.html"]]];
		} 
} 
else { // for any other top level tableview rows
		if (indexPath.row == 0) { // the first subrow
			[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.ebay.com.au"]]];
		} else { //any other subrows
			[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.ebay.com.au"]]];
		}
	}

	uiWebView.scalesPageToFit = YES; // uiWebView - object of UiWebview

	[webViewController.view addSubview: uiWebView];
	
	[self.navigationController pushViewController:webViewController animated:YES];
	
}
Of course, for more tableview rows and/or subrows you would add more "else if" statements in between the "if" and the last "else".

Depending on the structure of your tables and classes you may need to play around with the code, but this should give you more than a general idea.

Best of luck!
ellawson is offline   Reply With Quote
Old 01-19-2012, 10:00 AM   #5 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 2
Bricolaureate is on a distinguished road
Default Help with the above code

Hi,
I'm a newbie also and I thought this code you provided would be my answer but I'm having trouble making it work and hope you can help (have tried other things to no avail)

The problem I have is that the selection keeps loading from the first row of the second table regardless of the selection from the first table. Can you see what I may be missing?

I copied your code bit from above and inserted my values as such:

Any help greatly appreciated!!

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath {

//Get the dictionary of the selected data source.
NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];

//Get the children of the present item.
NSArray *Children = [dictionary objectForKey:@"Children"];



if([Children count] == 0)
{


UIViewController *webViewController = [[[UIViewController alloc] init] autorelease];

UIWebView *uiWebView = [[[UIWebView alloc] initWithFrame: CGRectMake(0,0,320,480)] autorelease];
if ([self.title isEqualToString:@"FirstRowTitleName"]){ //if the tableview row with this title is selected
if (indexPath.row == 0) { //then the first subrow should open this webview URL
[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];
} else if (indexPath.row == 1) { //the second subrow
[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.amazon.com"]]];
} else { //any other subrows
[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.yahoo.com"]]];
}
} else if ([self.title isEqualToString:@"Body Blitz"]){ //if the tableview row with this title is selected
if (indexPath.row == 0) { //then the first subrow will open this webview URL
[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.coles.com.au"]]];
} else { //any other subrows will open this one
[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.cdu.edu.au.html"]]];
}
}
else { // for any other top level tableview rows
if (indexPath.row == 0) { // the first subrow
[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.ebay.com.au"]]];
} else { //any other subrows
[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.ebay.com.au"]]];
}
}

uiWebView.scalesPageToFit = YES; // uiWebView - object of UiWebview

[webViewController.view addSubview: uiWebView];

[self.navigationController pushViewController:webViewController animated:YES];

}



else {

//Prepare to tableview.
RootViewController *rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];

//Increment the Current View
rvController.CurrentLevel += 1;

//Set the title;
rvController.CurrentTitle = [dictionary objectForKey:@"Title"];

//Push the new table view on the stack
[self.navigationController pushViewController:rvController animated:YES];

rvController.tableDataSource = Children;

[rvController release];
}
}
Bricolaureate is offline   Reply With Quote
Reply

Bookmarks

Tags
table view, url, web view

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 363
11 members and 352 guests
condor304, dansparrow, Domele, dreamdash3, ilmman, LezB44, michelle, Sami Gh, shagor012, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:34 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0