iOS Development Discussion on developing apps for the iOS platform.

uiwebview problem


Post Reply New Thread Subscribe

 
Thread Tools
sagarshivam

 
Member Since: Jun 03, 2011
Posts: 54
sagarshivam is on a distinguished road

sagarshivam is offline
Dear All

I am facing some problem with uiwebview. In my split view based application, on tapping cell of left panel (uitableview) , corresponding file (located on server) should be viewed on detail view (right pane of uisplitview)

part of Maintable.m is:

Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    detailViewController.detailItem = [file_list_for_subproject objectAtIndex:indexPath.row];
	
}

detailviewcontroller.h is :

Code:
@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate> {
    
    UIPopoverController *popoverController;
    UIToolbar *toolbar;
    UIWebView *file_view;
    id detailItem;
    UILabel *detailDescriptionLabel;
	IBOutlet UIImageView *imgview;
}

@property (nonatomic, retain) IBOutlet UIToolbar *toolbar;

@property (nonatomic, retain) id detailItem;
@property (nonatomic, retain) IBOutlet UILabel *detailDescriptionLabel;
@property (nonatomic,retain) UIWebView *file_view;
@property (nonatomic ,retain) UIImageView *imgview;
@end

and part of detailviewcontroller.m is:

Code:
- (void)setDetailItem:(id)newDetailItem {
    if (detailItem != newDetailItem) {
        [detailItem release];
        detailItem = [newDetailItem retain];
        NSString *fname1= [NSString stringWithFormat:@"%@",detailItem];
	NSLog(@"file name passed is %@",fname1);
        //fname is getting displayed properly
        [self configureView];
		
    }

    if (popoverController != nil) {
        [popoverController dismissPopoverAnimated:YES];
    }        
}


- (void)configureView {
  
    detailDescriptionLabel.text = [detailItem description];   
	//CGRect frame= [[UIScreen mainScreen] applicationFrame];
	//UIWebView *webview = [[UIWebView alloc] initWithFrame:frame];
	//self.file_view.backgroundColor = [UIColor redColor];
	NSURL *urpath = [NSURL URLWithString:@"http://172.22.79.169/~spp/Cref.pdf"];
	NSURLRequest *req = [NSURLRequest requestWithURL:urpath];
	[self.file_view loadRequest:req];
	[self.view addSubview:file_view];
	[self.file_view release];
}
But pdf is not getting displayed. Where am I making mistake?
QUOTE Thanks
Nethfel

 
Member Since: Feb 25, 2009
Posts: 2,084
Nethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of light
Mac Specs: 2012 Non-retina MBP, 2.6GHz i7, 8GB RAM, Antiglare Screen

Nethfel is offline
No idea. Not near enough code to explain what is going on. What is file_view? it would appear to be the webview, but no where is it being allocated, but it is being released (why?, and from what it appears, I hope you don't release it again somewhere if there aren't enough retains on it). Does http://172.22.79.169/~spp/Cref.pdf even exist? it's not accessible via the internet, so there is no way for us to test it. Have you put any of the delegate methods in for the web view so you can get responses back from the webview about any errors that may occur?

My Macs: 2012 Non-Retina 15" MBP; Mac mini G4, 1.25 GHz, 512m ram (server); Late 2011 11" MBA, 1.8GHz i7, 4Gig Ram, 256Gig SSD, HD3000; Powerbook 12" G4 1.33GHz running Debian as a server; Apple TV (1080p version)
QUOTE Thanks
sagarshivam

 
Member Since: Jun 03, 2011
Posts: 54
sagarshivam is on a distinguished road

sagarshivam is offline
Left panel is 3 level deep and each level is uitabletype. So on tapping row of first table, second table is pushed and similarly on tapping cell of second table , third table is pushed (which contains a list of files located on local server, ex: http://172.22.79.169/~spp/Cref.pdf .These files are absolutely accessible)

Till the time, third table is pushed, detail view shows activityindicator and it keeps on moving. It works fine.

Now , on tapping third table's cell, webview should be loaded in detail view and corresponding tapped file (variable detailItem is every time assigned with the URL of file) should be loaded in uiwebview. And the problem is that uiwebview is not getting loaded and file is not viewed and finally activityindicator keeps on moving.

I am sure that the problem is related to uiwebview and I am not using IB to make either of interface.

Codes are :

for last level table (I am not posting code for other tables as everything related to them are proper functioning.), code is:

SubTable.h

Code:
#import <UIKit/UIKit.h>
@class DetailViewController;
@interface SubTable : UITableViewController {
	NSArray *file_list_for_subproject;
	DetailViewController *detailViewController;
	
}

@property (nonatomic, retain) NSArray *file_list_for_subproject;
@property (nonatomic,retain) DetailViewController *detailViewController;
@end
SubTable.m

Code:
#import "SubTable.h"
#import "DetailViewController.h"
#import "SecondLevelViewController.h"

@implementation SubTable

@synthesize file_list_for_subproject,detailViewController;
- (void)viewDidLoad {
    [super viewDidLoad];
	detailViewController = [[DetailViewController alloc] init];
	self.clearsSelectionOnViewWillAppear = NO;
	self.navigationItem.rightBarButtonItem = self.editButtonItem;
     }

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
 
    return [file_list_for_subproject count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"any-cell"];
	UILabel *labelView = NULL;
	if (cell == nil) {
		
		cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"any-cell"] autorelease];
		cell.selectionStyle = UITableViewCellSelectionStyleGray; 
		[[[cell subviews] objectAtIndex:0] setTag:111];
		labelView = [[UILabel alloc] initWithFrame: CGRectMake(8, 0, 300, 44)]; 
		[labelView setBackgroundColor:[UIColor clearColor]]; 
		[labelView setTag:222];
		[labelView setFont:[UIFont boldSystemFontOfSize:20]];
		[cell addSubview:labelView];
		[labelView release];
		UIView *cellView = [cell viewWithTag:111];
		if (row % 2)
			[cellView setBackgroundColor:[UIColor whiteColor]]; 
		else
			[cellView setBackgroundColor:[UIColor colorWithRed:0.90f green:0.95f blue:1.0f alpha:1.0f]];
		
		[(UILabel *)[cell viewWithTag:222] setText:[file_list_for_subproject objectAtIndex:indexPath.row]]; 
		
	}	
	return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    detailViewController.detailItem = [file_list_for_subproject objectAtIndex:indexPath.row];
	
}  
/* variable detailitem in DetailViewController class is assigned file url every time any cell is tapped here. And I have checked using NSLog that detailItem is containing that url. Everything works fine till here 
*/
DetailViewController.h is:
Code:
#import <UIKit/UIKit.h>

@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate,UIWebViewDelegate> {
    
    UIPopoverController *popoverController;
    UIToolbar *toolbar;
    UIWebView *webview;
    id detailItem;
    UILabel *detailDescriptionLabel;
   UIActivityIndicatorView *uiact;
	
}

@property (nonatomic, retain) IBOutlet UIToolbar *toolbar;

@property (nonatomic, retain) id detailItem;
@property (nonatomic, retain) IBOutlet UILabel *detailDescriptionLabel;
@property (nonatomic,retain) UIWebView *webview;
@property (nonatomic ,retain) UIActivityIndicatorView *uiact;
@end
DetailViewController.m is:

Code:
#import "DetailViewController.h"

@interface DetailViewController ()
@property (nonatomic, retain) UIPopoverController *popoverController;
@end

@implementation DetailViewController

@synthesize toolbar, popoverController, detailItem, detailDescriptionLabel,webview,uiact;

- (void)setDetailItem:(id)newDetailItem {
    if (detailItem != newDetailItem) {
        [detailItem release];
        detailItem = [newDetailItem retain]; //detailItem contains url of file                   
                                                          // tapped in table
      [self performSelector:@selector(startWebViewLoad) withObject:nil afterDelay:0];
    }
	
    if (popoverController != nil) {
        [popoverController dismissPopoverAnimated:YES];
    }        
}

- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc {
    
    barButtonItem.title = @"Root List";
    NSMutableArray *items = [[toolbar items] mutableCopy];
    [items insertObject:barButtonItem atIndex:0];
    [toolbar setItems:items animated:YES];
    [items release];
    self.popoverController = pc;
}

- (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
    
    NSMutableArray *items = [[toolbar items] mutableCopy];
    [items removeObjectAtIndex:0];
    [toolbar setItems:items animated:YES];
    [items release];
    self.popoverController = nil;
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void)startWebViewLoad {
	NSLog(@"detail item is ------ %@", detailItem); // It is displaying
                                                                           //  correct file URL 
	CGRect frame= [[UIScreen mainScreen] applicationFrame];
	UIWebView *webview1 = [[UIWebView alloc] initWithFrame:frame];
	webview1.backgroundColor = [UIColor redColor]; // I cant see red 
                                                                           //color in detail view
	webview1.scalesPageToFit =YES;
	self.webview =webview1;
	NSString *file_path=detailItem;
	NSURL *urlpath = [NSURL URLWithString:file_path];
	NSURLRequest *reqobj = [NSURLRequest requestWithURL:urlpath];
	[self.webview loadRequest:reqobj];
	[self.view addSubview: self.webview];
	[webview1 release];
    //there is no UIWebView getting loaded, I guess and activityindicator keeps on moving
}


- (void)viewDidLoad{
	
	UIActivityIndicatorView *progressWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(260,260,90,90)];
	progressWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
	progressWheel.hidesWhenStopped = YES;
	self.uiact = progressWheel;
	[self.view addSubview: self.uiact];
	[self.uiact startAnimating];
	[progressWheel release]; 	
	
}

// Activityindicator should start right from Root table view, and its working well as expected

I want to know where am I making mistake? And why file is not getting diplayed in uiwebview in detailview. Files are completely accessible and they are well displayed when using in different project.
QUOTE Thanks
sagarshivam

 
Member Since: Jun 03, 2011
Posts: 54
sagarshivam is on a distinguished road

sagarshivam is offline
any suggestion??
QUOTE Thanks
Nethfel

 
Member Since: Feb 25, 2009
Posts: 2,084
Nethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of light
Mac Specs: 2012 Non-retina MBP, 2.6GHz i7, 8GB RAM, Antiglare Screen

Nethfel is offline
I see a couple of things.

First note - you're using sizing that is wrong.

CGRect frame= [[UIScreen mainScreen] applicationFrame];
UIWebView *webview1 = [[UIWebView alloc] initWithFrame:frame];

You shouldn't be requesting the frame of the UIScreen for setting the webview frame, you should be requesting the bounds of the view that you're adding the webview into (the detail controllers view). The frame of the screen is going to be the full size of the screen that the application window resides in rather then the size of the detail view which will be different depending on landscape or portrait orientation.

And why are you doing this:

[self performSelector:@selector(startWebViewLoad) withObject:nil afterDelay:0]; ?

you should just do:

[self startWebViewLoad];

All you're doing is adding in additional method calls that aren't necessary in this case.

You're also using the activity indicator in a funky way - it should be spinning during the time of load, which you should activate through the UIWebViewDelegate methods which you haven't implemented (but need to).

Your code is odd though. You're creating a detailViewController in the subtable class, but no where do I see where you're setting the detail view controller of the splitviewcontroller to be that controller you allocated. Just because it may have the same name and be of the same class of another instance doesn't mean you have access to instance A through instance B of a given class.

It looks to me like you don't quite understand how to communicate between the master and the detail view of the split view controller, and in that you are never really telling the ACTUAL detail view controller to load and display the content. So my guess based upon the code you have posted is because you aren't actually communicating with the actual instance of the detail view that is really on the screen but rather the one you alloc'd in the subtable.m file which is different from the one that is in the split view detail panel.

My Macs: 2012 Non-Retina 15" MBP; Mac mini G4, 1.25 GHz, 512m ram (server); Late 2011 11" MBA, 1.8GHz i7, 4Gig Ram, 256Gig SSD, HD3000; Powerbook 12" G4 1.33GHz running Debian as a server; Apple TV (1080p version)
QUOTE Thanks
sagarshivam

 
Member Since: Jun 03, 2011
Posts: 54
sagarshivam is on a distinguished road

sagarshivam is offline
@above,

Plz see the below modified code. And what to say if I can see the background colour of uiwebview which i set using webview.background = [UIColour redcolour];
It means that uiwebview is getting loaded but document is not loaded. Am I correct? Plz rectify me.

DetailViewController.h is:
Code:
#import <UIKit/UIKit.h>

@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate,UIWebViewDelegate> {
    
    UIPopoverController *popoverController;
    UIToolbar *toolbar;
    
    id detailItem;
    UILabel *detailDescriptionLabel;
    UIWebView *webview;
    UIActivityIndicatorView *actview;
}

@property (nonatomic, retain) IBOutlet UIToolbar *toolbar;

@property (nonatomic, retain) id detailItem;
@property (nonatomic, retain) IBOutlet UILabel *detailDescriptionLabel;
@property (nonatomic,retain) IBOutlet UIWebView *webview;
@property (nonatomic, retain) UIActivityIndicatorView *actview;
@end
DetailViewController.m is
Code:
#import "DetailViewController.h"
#import "RootViewController.h"


@interface DetailViewController ()
@property (nonatomic, retain) UIPopoverController *popoverController;
- (void)configureView;
-(void)startWebViewLoad;
@end



@implementation DetailViewController

@synthesize toolbar, popoverController, detailItem, detailDescriptionLabel,webview,actview;


- (void)setDetailItem:(id)newDetailItem {
	
    if (detailItem != newDetailItem) {
        [detailItem release];
        detailItem = [newDetailItem retain];
       // NSLog(@"set detail item  ****** %@", detailItem);
       
        [self configureView];
	[self startWebViewLoad];
    }

    if (popoverController != nil) {
        [popoverController dismissPopoverAnimated:YES];
    }        
}


- (void)configureView {
    // Update the user interface for the detail item.
	[actview stopAnimating];
    detailDescriptionLabel.text = [detailItem description];   
}


#pragma mark -
#pragma mark Split view support

- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc {
    
    barButtonItem.title = @"Root List";
    NSMutableArray *items = [[toolbar items] mutableCopy];
    [items insertObject:barButtonItem atIndex:0];
    [toolbar setItems:items animated:YES];
    [items release];
    self.popoverController = pc;
}


// Called when the view is shown again in the split view, invalidating the button and popover controller.
- (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
    NSLog(@"in viewcontroller landscape mode");
    NSMutableArray *items = [[toolbar items] mutableCopy];
    [items removeObjectAtIndex:0];
    [toolbar setItems:items animated:YES];
    [items release];
    self.popoverController = nil;
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}


- (void)startWebViewLoad {
	[actview stopAnimating];
	NSLog(@"detail item is ------ %@", detailItem);
	CGRect frame= [[UIScreen mainScreen] applicationFrame];
	webview = [[[UIWebView alloc] initWithFrame:frame] autorelease];
	webview.scalesPageToFit =YES;
	webview.backgroundColor = [UIColor clearColor]; // I can see the color whatever set here on launch of application in detailview part.
	NSURL *urlpath = [NSURL URLWithString:detailItem];
	NSURLRequest *reqobj = [NSURLRequest requestWithURL:urlpath];
	[webview loadRequest:reqobj];
	[webview reload];
	[self.view addSubview:webview];
	NSLog(@"done");  //both the NSLog in this method are displaying expected result on each tap of cell in left pane
	
    
}

- (void)viewDidLoad{
	UIActivityIndicatorView *progressWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(260,260,90,90)];
	
	progressWheel.activityIndicatorViewStyle =  UIActivityIndicatorViewStyleGray;
	progressWheel.hidesWhenStopped = YES;
	self.actview = progressWheel;
	[self.view addSubview: self.actview];
	[self.actview startAnimating];
       [progressWheel release];
	[super viewDidLoad];
		
	
}
QUOTE Thanks
Nethfel

 
Member Since: Feb 25, 2009
Posts: 2,084
Nethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of light
Mac Specs: 2012 Non-retina MBP, 2.6GHz i7, 8GB RAM, Antiglare Screen

Nethfel is offline
Can you just zip up the whole project and upload it? This seeing bits and pieces is hard to tell exactly what is going on where. From the earlier post, you're not modifying the actual detail view. But you're claiming from this post that you are. The only way that would make sense is if you're using the property of the SubTable to associate it to the real detail view, but if you are, then this hunk of code:

detailViewController = [[DetailViewController alloc] init];
self.clearsSelectionOnViewWillAppear = NO;

is kinda worthless.

You're also still not implementing the UIWebViewDelegate (how did you plan to know when the webview was done loading to stop the activity indicator without it? set an NSTimer and manually check it every X seconds? you need to use the delegate, it's cleaner and also has error methods that you can have feedback as to why something didn't load)

My Macs: 2012 Non-Retina 15" MBP; Mac mini G4, 1.25 GHz, 512m ram (server); Late 2011 11" MBA, 1.8GHz i7, 4Gig Ram, 256Gig SSD, HD3000; Powerbook 12" G4 1.33GHz running Debian as a server; Apple TV (1080p version)
QUOTE Thanks
sagarshivam

 
Member Since: Jun 03, 2011
Posts: 54
sagarshivam is on a distinguished road

sagarshivam is offline
In my project, every thing works well except loading of file. So, I made one small project (selected Window based app for iPad from template and then did nothing in MainWindow.xib), I am uploading that project. Kindly resolve the issue.

On tapping the cell in Second level, corresponding file (lying on intranet or internet) should be opened. But its not happening now.

I want to learn further with my mistakes, so I will try with actual project after I learn my mistake from here.

Demo_App.zip

Regards
Sagar
QUOTE Thanks
Nethfel

 
Member Since: Feb 25, 2009
Posts: 2,084
Nethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of light
Mac Specs: 2012 Non-retina MBP, 2.6GHz i7, 8GB RAM, Antiglare Screen

Nethfel is offline
There were a bunch of little things. I didn't check 100% of your code, so there may still be memory leaks in places - I only checked and fixed your handling of the detail view and the webview.

Here's the corrected version...

ps - Always when uploading your projects, delete the build folder from within the project prior to uploading - the build has to be redone anyway and significantly increases the size of a project - especially if you have graphical assets as part of the project.

pss - I also didn't fix your split controller portrait view problem - I figure that's up to you to either correct or force your app to only be landscape.
Attached Files
File Type: zip Demo_AppCorrected.zip (36.8 KB, 15 views)

My Macs: 2012 Non-Retina 15" MBP; Mac mini G4, 1.25 GHz, 512m ram (server); Late 2011 11" MBA, 1.8GHz i7, 4Gig Ram, 256Gig SSD, HD3000; Powerbook 12" G4 1.33GHz running Debian as a server; Apple TV (1080p version)

Last edited by Nethfel; 09-16-2011 at 09:07 AM.
QUOTE Thanks
sagarshivam

 
Member Since: Jun 03, 2011
Posts: 54
sagarshivam is on a distinguished road

sagarshivam is offline
Thanks a lot, a lot for the precious help. I really need to work harder on basics.

UiWebView is unable to display MS-office file type (doc, docx, xls, xlsx, ppt, pptx etc).
How can that be done?

Thanks a lot once again
QUOTE Thanks

Post Reply New Thread Subscribe


« Development Team | Adding wxWidgets to Xcode »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Problem with copy and paste that does not paste the more recent copy? pcortez Switcher Hangout 22 08-01-2012 01:28 PM
diagnosing kernel task/CPU problem on Macbook Air nick_harambee Apple Notebooks 9 08-20-2011 07:20 AM
could this be an OS problem? Anyuta OS X - Operating System 0 11-22-2010 04:50 PM
Strange iweb problem Anyuta Web Design and Hosting 0 09-27-2010 12:46 PM
2009 MBP - Possible Trackpad Problem tricky10 Apple Notebooks 6 09-09-2010 07:01 AM

All times are GMT -4. The time now is 04:06 PM.

Powered by vBulletin
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?