My problem here is that 2 data pointers are doing what they supposed to be doing by pointing to data in a SQL database except whenever they are called in the two methods webViewDidStartLoad and webViewDidFinishLoad.
The other 2 data pointer(total 4) which belongs to the same SQL database have no problem functioning properly when called in all methods. Only the username and password pointers are giving me problems by pointing to rubbish code in the two previously mentioned methods..
In ControllerA, when i select a row, it will push me to the WebViewController as the code below shows.
When i run the program and click on a row in the tableView, it pushes the WebViewController and i will get a EXC_BAD_ACCESS at those 4 points show below.
The below debugger shows when the first EXC_BAD_ACCESS will appear. if you remove that line with the EXC_BAD_ACCESS error, the next EXC_BAD_ACCESS will occur as shown above in order, respectively.
Thank You for taking the time to read my lengthy code.
Looking forward to your advice!
The other 2 data pointer(total 4) which belongs to the same SQL database have no problem functioning properly when called in all methods. Only the username and password pointers are giving me problems by pointing to rubbish code in the two previously mentioned methods..
In ControllerA, when i select a row, it will push me to the WebViewController as the code below shows.
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (internetBrower == nil) {
internetBrower = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];
}
Login *loginObj = [appDelegate.loginArray objectAtIndex:indexPath.row];
//Get the detail view data if it does not exists.
//We only load the data we initially want and keep on loading as we need.
[loginObj hydrateDetailViewData];
//--passing the data to WebViewController
internetBrower.loginObj = loginObj;
//--Push WebViewController
[self.navigationController pushViewController:internetBrower animated:YES];
internetBrower = nil;
}
When i run the program and click on a row in the tableView, it pushes the WebViewController and i will get a EXC_BAD_ACCESS at those 4 points show below.
Code:
#import "WebViewController.h"
#import "FYP_TEST_1AppDelegate.h"
#import "MainLoginController.h"
#import "Login.h"
@implementation WebViewController
@synthesize myWebView, loginObj, urlTextField, activity;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void) showWebView{
NSLog(@"showWebView desc: %@", loginObj.loginDesc);
NSLog(@"showWebView url: %@", loginObj.loginURL);
NSLog(@"showWebView username: %@", loginObj.loginUserName);
NSLog(@"showWebView password: %@", loginObj.loginPassword);
NSURL *url = [NSURL URLWithString:loginObj.loginURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:request];
}
-(IBAction)openSafari:(id)sender{
[[UIApplication sharedApplication] openURL:myWebView.request.URL];
}
-(void) webViewDidStartLoad:(UIWebView *)webView{
NSLog(@"viewDidStartLoad desc: %@", loginObj.loginDesc);
NSLog(@"viewDidStartLoad url: %@", loginObj.loginURL);
[B]EXC_BAD_ACCESS ->[/B]NSLog(@"viewDidStartLoad username: %@", loginObj.loginUserName);
[B]EXC_BAD_ACCESS ->[/B]NSLog(@"viewDidStartLoad password: %@", loginObj.loginPassword);
//--illusion that the webpage has already started loading..
NSString *currentURL = myWebView.request.URL.absoluteString;
if (!(currentURL == NULL)) {
urlTextField.text = currentURL;
}
[activity startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(@"webViewDidFinishLoad desc: %@", loginObj.loginDesc);
NSLog(@"webViewDidFinishLoad url: %@", loginObj.loginURL);
[B]EXC_BAD_ACCESS ->[/B]NSLog(@"webViewDidFinishLoad username: %@", loginObj.loginUserName);
[B]EXC_BAD_ACCESS ->[/B]NSLog(@"webViewDidFinishLoad password: %@", loginObj.loginPassword);
[activity stopAnimating];
NSString *usrAmazon = [NSString stringWithFormat:@"document.getElementById('ap_email').value='tom@tom.com';"];
NSString *passAmazon = [NSString stringWithFormat:@"document.getElementById('ap_password').value='secret';"];
[myWebView stringByEvaluatingJavaScriptFromString:usrAmazon];
[myWebView stringByEvaluatingJavaScriptFromString:passAmazon];
//--extracting title from the HTML and printing it on the UIWebView's Title
NSString *webTitle = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
self.title = webTitle;
}
- (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.
}
#pragma mark - View lifecycle
- (void)viewDidLoad{
[super viewDidLoad];
NSLog(@"viewDidLoad desc: %@", loginObj.loginDesc);
NSLog(@"viewDidLoad url: %@", loginObj.loginURL);
NSLog(@"viewDidLoad username: %@", loginObj.loginUserName);
NSLog(@"viewDidLoad password: %@", loginObj.loginPassword);
myWebView.delegate = self;
//--Clear all Cache and Cookies so everytime webview is shown, it will be brand new
//Set Cache
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
//Clear All Cookies
for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
//if([[cookie domain] isEqualToString:someNSStringUrlDomain]) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
[self showWebView];
// Do any additional setup after loading the view from its nib.
}
-(void)viewDidUnload{
[self setMyWebView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
-(void) viewWillAppear:(BOOL)animated{
NSLog(@"viewWillAppear desc: %@", loginObj.loginDesc);
NSLog(@"viewWillAppear url: %@", loginObj.loginURL);
NSLog(@"viewWillAppear username: %@", loginObj.loginUserName);
NSLog(@"viewWillAppear password: %@", loginObj.loginPassword);
[super viewWillAppear:animated];
//--set title of webview first to create the illusion that it is loading the page already. later on when page finish load, will grab the title from the HTML and replace this.
self.title = loginObj.loginDesc;
urlTextField.text = loginObj.loginURL;
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
-(void) dealloc{
[myWebView release];
[activity release];
[urlTextField release];
//[loginObj release];
[super dealloc];
}
@end
The below debugger shows when the first EXC_BAD_ACCESS will appear. if you remove that line with the EXC_BAD_ACCESS error, the next EXC_BAD_ACCESS will occur as shown above in order, respectively.
Code:
2012-03-06 06:24:36.527 FYP_TEST_1[208:707] hydrateDetailViewData is called
2012-03-06 06:24:36.529 FYP_TEST_1[208:707] detailview is not HYDRATED
2012-03-06 06:24:36.539 FYP_TEST_1[208:707] self.loginURL = http://www.facebook.com
2012-03-06 06:24:36.542 FYP_TEST_1[208:707] self.loginUserName = tom@tom.com
2012-03-06 06:24:36.546 FYP_TEST_1[208:707] self.loginPassword = secret
2012-03-06 06:24:37.074 FYP_TEST_1[208:707] viewDidLoad desc: Facebook
2012-03-06 06:24:37.076 FYP_TEST_1[208:707] viewDidLoad url: http://www.facebook.com
2012-03-06 06:24:37.078 FYP_TEST_1[208:707] viewDidLoad username: tom@tom.com
2012-03-06 06:24:37.080 FYP_TEST_1[208:707] viewDidLoad password: secret
2012-03-06 06:24:37.095 FYP_TEST_1[208:707] showWebView desc: Facebook
2012-03-06 06:24:37.096 FYP_TEST_1[208:707] showWebView url: http://www.facebook.com
2012-03-06 06:24:37.099 FYP_TEST_1[208:707] showWebView username: tom@tom.com
2012-03-06 06:24:37.101 FYP_TEST_1[208:707] showWebView password: secret
2012-03-06 06:24:37.105 FYP_TEST_1[208:707] viewWillAppear desc: Facebook
2012-03-06 06:24:37.107 FYP_TEST_1[208:707] viewWillAppear url: http://www.facebook.com
2012-03-06 06:24:37.109 FYP_TEST_1[208:707] viewWillAppear username: tom@tom.com
2012-03-06 06:24:37.111 FYP_TEST_1[208:707] viewWillAppear password: secret
[Switching to process 8963 thread 0x2303]
warning: Unable to read symbols for /Users/Tom/Library/Developer/Xcode/iOS DeviceSupport/5.0.1 (9A405)/Symbols/System/Library/Extensions/IMGSGX535GLDriver.bundle/IMGSGX535GLDriver (file not found).
warning: No copy of IMGSGX535GLDriver.bundle/IMGSGX535GLDriver found locally, reading from memory on remote device. This may slow down the debug session.
[Switching to process 8451 thread 0x2103]
2012-03-06 06:24:37.818 FYP_TEST_1[208:707] viewDidStartLoad desc: Facebook
2012-03-06 06:24:37.820 FYP_TEST_1[208:707] viewDidStartLoad url: http://www.facebook.com
[Switching to process 7171 thread 0x1c03]
(gdb)
Thank You for taking the time to read my lengthy code.
Looking forward to your advice!
Last edited: