Hello,
I'm very new and thankful for any help.
I have been working on a drill down app based on the tutorial that is supposed to feed the URL in the detailViewController.
I have success in loading the URL but can only pull the URL from the first row of the second table, when really the URL should be the first line of the second table based on x line of the first table.
I tried nested if statements and could not get that to work. And I have been trying to find the correct code to load it from the data in the plist.
I would be happy with either solution (if statements or data in the plist) though I think the data would make cleaner code (I don't really want to hard code in all the URLs)
Please help..and thank you.
- (void)tableView

UITableView *)tableView didSelectRowAtIndexPath

NSIndexPath *)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"];
//this doesn't work// NSString *MyUrl = [(NSString *)object_getClassName(data.MyURL)];
if([Children count] == 0) {
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
UIWebView *uiWebView = [[[UIWebView alloc] initWithFrame: CGRectMake(0,0,320,480)] autorelease];
if ([self.title isEqualToString:@"Title One"]){ //if the tableview row with this title is selected
if (indexPath.row == 0) { //the [uiWebView loadRequest:
[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:@"Item 2"]){ //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.wikipedia.com"]]];
} else { //any other subrows
[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.ebay.com.au"]]];
}
}
uiWebView.scalesPageToFit = YES; // uiWebView - object of UiWebview
[dvController.view addSubview:uiWebView];
[self.navigationController pushViewController:dvController animated:YES];
}
[dvController release];
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];
}
}
And here is the .plist
Rows - Array
Item 0 - Dictionary
Title String Title One
Children Array
Item 0 Dictionary
Title String Child One
MyURL String "Http://www.google.com"
Item 1 Dictionary
Title String Child Two
MyURL String "Http://www.ebay.com"
Item 1 - Dictionary
Title String Title Two
Children Array
Item 0 Dictionary
Title String Second Child One
My URL Sting "Http://www.target.com"
etc...