Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ct2k7

macrumors G3
Original poster
Aug 29, 2008
8,383
3,439
London
Hello, I'm trying to pass the user on to the interface based on their cell selection in the UITableView, ie, if the user selects cell 1, they are taken to view model 2, containing UIWebView. UIWebView then displays local file, cell1.html.
Currently, I've manage to get placeholder using:

Code:
selectedCellText.text = selectedCell;

to display the name of the cell selected. How do I get it to directly pass to the UIWebView, stick UIWebView in the interface and link it using:

Code:
[COLOR=#2b91af]UIWebView[/COLOR] *myWebView = [[[COLOR=#2b91af]UIWebView[/COLOR] alloc] initWithFrame:frame]; 
[COLOR=#2b91af]NSBundle[/COLOR] *mainBundle = [[COLOR=#2b91af]NSBundle[/COLOR] mainBundle]; 
[COLOR=#2b91af]NSString[/COLOR] *stringUrl = [mainBundle pathForResource:@[COLOR=#800000]"selectedCell"[/COLOR] ofType:@[COLOR=#800000]"html"[/COLOR]]; 
NSURL *baseUrl = [NSURL fileURLWithPath:stringUrl]; 
[COLOR=#2b91af]NSURLRequest[/COLOR] *urlRequest = [[COLOR=#2b91af]NSURLRequest[/COLOR] requestWithURL:baseUrl]; 
 
[myWebView loadRequest:urlRequest];

My other issue is that some of the cell names have spaces in them, and for simplicity, I'd like to ensure that there are no spaces (actually, will it even work with spaces in the name, I assume with %20 ?
Thanks
 
This is not nil!

Hi, I'm using a UIWebView in my app, and to determine the URL:

Code:
NSString *urlAddress = [[NSBundle mainBundle] pathForResource:selectedCell ofType:@"htm"];

However, the system complains that the urladdress variable is nil :(

selectedCell is defined by:

Code:
 IBOutlet UILabel *selectedCellText;
 NSString *selectedCell;

What's wrong with this currently?
 
First, selectedCell is not supported under UITableView, so I'm not sure what you're doing there. Second, maybe include your code for tableView:didSelectRowAtIndexPath: so we can see how you're handling the table row selection.
 
That would probably help, but I can't really define it since the cell needs to be selected :(
 
Hmm, with selectedCell, all I'm doing is getting back the text of the cell which the user had gone through, gained from AddObject property.

Here's what's happening:

Code:
[COLOR=#000000][FONT=monospace]- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]//get selected cell NSString *selectedCell = [ItemsList objectAtIndex:indexPath.row]; [/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]//Init the detail view controller nd display it like! [/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]]; dvController.selectedCell = selectedCell; [/FONT][/COLOR]
[COLOR=#000000][FONT=monospace][self.navigationController pushViewController:dvController animated:YES]; [dvController release]; [/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]dvController = nil; [/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]}[/FONT][/COLOR]
 
Okay, that looks fine (assuming ItemsList is an instance variable and not a class; tip: you should name your variables starting with lower-case; it's a common Objective-C convention so that they are not confused with class names which typically start with upper-case).

So, can we see the code for DetailViewController (.h and .m) now?
 
Code:
//
//  DetailViewController.h
//  AS Physics Revision
//
//  Created by Shamil Nunhuck on 01/07/2010.
//  Copyright 2010 Shamil Nunhuck. All rights reserved.
//
#import <UIKit/UIKit.h>

@interface DetailViewController : UIViewController {
 
 IBOutlet UILabel *selectedCellText;
 NSString *selectedCell;
 IBOutlet UIWebView *webView;
}
@property (nonatomic, retain) NSString *selectedCell;
@property (nonatomic, retain) UIWebView *webView;
@end
//
//  DetailViewController.m
//  AS Physics Revision
//
//  Created by Shamil Nunhuck on 01/07/2010.
//  Copyright 2010 Shamil Nunhuck. All rights reserved.
//
#import "DetailViewController.h"
 
@implementation DetailViewController
@synthesize selectedCell;
@synthesize webView;
/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/
- (void)viewDidLoad {
    [super viewDidLoad];
 //Display the selected cell.
 selectedCellText.text = selectedCell;
 //Set the title of the navigation bar
 self.navigationItem.title = selectedCell;
 
 
 
 NSString *urlAddress = @"[URL]http://www.google.com[/URL]";
 //NSString *urlAddress =[[NSBundle mainBundle] pathForResource:@"selectedCell" ofType:@"htm"];}
 NSURL *url = [NSURL URLWithString:urlAddress];
 NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
 [webView loadRequest:requestObj];
 
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
 // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
 
 // Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
 // Release any retained subviews of the main view.
 // e.g. self.myOutlet = nil;
}

- (void)dealloc {
 [selectedCell release];
 [selectedCellText release];
    [super dealloc];
}

@end

Thanks for the tip :)
 
So, the selectedCellText UILabel is being set to what you expect, right?

Yep, and it seems to be working, the only issue is that the contents of the html file (I changed it) is not showing up in the uiwebview
 
Yep, and it seems to be working, the only issue is that the contents of the html file (I changed it) is not showing up in the uiwebview
Okay. Without knowing what urlAddress is getting set to and what the contents of your application bundle (project folder) are, it's hard to say why it's not able to load the NSURLRequest.

Following are minor, unrelated concerns:

P.S. Why don't you have a property defined for your UILabel *selectedCellText?

P.S.S. For ivars you've defined properties (selectedCell, webView) for, it's a good habit to reference them using their accessors (self.selectedCell or [self setWebView:...]) rather than directly (like you're doing in [webView loadRequest: ...])
 
Okay. Without knowing what urlAddress is getting set to and what the contents of your application bundle (project folder) are, it's hard to say why it's not able to load the NSURLRequest.

Following are minor, unrelated concerns:

P.S. Why don't you have a property defined for your UILabel *selectedCellText?

P.S.S. For ivars you've defined properties (selectedCell, webView) for, it's a good habit to reference them using their accessors (self.selectedCell or [self setWebView:...]) rather than directly (like you're doing in [webView loadRequest: ...])

I'll PM you the contents, rather not let it out in public :)

You've raised two good points there :) I'll implement them in the next development week :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.