we recently upgraded to IOS 8 (and compiled the application).
we saw that tables with text are not showing well anymore (we use UIWebView).
did anyone encounter this? is this a known issue or a bug?
this is the code:
#import "ViewController.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UIWebView *viewWeb;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString* fullPath = #"/Users/deployment/Downloads/table-2.ppt";
[_viewWeb loadData:[NSData dataWithContentsOfFile:fullPath] MIMEType:#"application/vnd.ms-powerpoint" textEncodingName:nil baseURL:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
thanks!
Are you tried this code...?
UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(10.0,10.0,300,300)];
[webView setScalesPageToFit:YES];
webView.backgroundColor=[UIColor clearColor];
NSString *ppt = [[NSBundle mainBundle] pathForResource:#"test" ofType:#"ppt"];
NSURL *pptURL = [NSURL fileURLWithPath:ppt];
NSURLRequest *request = [NSURLRequest requestWithURL:pptURL];
[webView loadRequest:request];
[self.view addSubview:webView];
If this code also not worked with your ppt file. Please share your ppt file too. This code working in my case. May be some issue with presentation file.
Related
If I add a uiwebview using storyboard it works great. But webviews that is added programmatically not scrolling.
self.webview=[[UIWebView alloc] init];
path=[[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"];
[self.webview setFrame:CGRectMake(-200, 0, 200, 300)];
[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
[self.view addSubview:self.webview];
UIWebview is added to a View programmatically using the below code:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width,600)];
[webview setBackgroundColor:[UIColor redColor]];
NSString *url=#"http://www.facebook.com";
NSURL *nsurl=[NSURL URLWithString:url];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webview loadRequest:nsrequest];
[self.view addSubview:webview];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
First of all I would like to thank you reading this and helping me out if you know the answer, I am a bit of a newby to iOS and there is an issue that is driving me crazy.
I have an App that works perfectly in iOS5, it has an UITableVIewController and clicking on a row takes you to an UIView with a UIWebView. The idea is that the URL of the webpage to load is passed from the UITableViewController in this way.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if (([[segue identifier] isEqualToString:#"ViewWeb"])) {
WebViewController *detailViewController = [segue destinationViewController];
detailViewController.title=parameter;
detailViewController.detailItem = parameterURL;
}
}
Then in the WebViewController I use the following code. I declare everything in the .h:
#import <UIKit/UIKit.h>
#interface WebViewController : UIViewController <UIWebViewDelegate>{
IBOutlet UIWebView *webView;
NSString *detailItem;
}
#property(strong,nonatomic) IBOutlet UIWebView *webView;
#property (strong, nonatomic) NSString *detailItem;
#end
And In my .m I use the following code to load the URL:
#interface WebViewController ()
#end
#implementation WebViewController
#synthesize webView;
#synthesize detailItem;
- (void)viewDidLoad
{
[super viewDidLoad];
//Create a URL object.
NSURL *url = [NSURL URLWithString:detailItem];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
}
This is working perfectly fine in the iOS5 simulator, but in iOS6, the UIWebWiew remains blank and doesn't load up. I have read this solution UIWebView not loading URL when URL is passed from UITableView but placing the code in the (void)viewWillAppear:(BOOL)animated does not solve the issue. It works perfectly fine if I hard code the URL, so I am totally lost as to how to solve this.
Thank you very much in advance, I know everyone here is really busy and the fact that great guys take a few minutes to hep me is something amazing.
following a post presented here, I tried to load a view defined in a XIB file into a view, currently being displayed. Basically, what I want to do is to replace the middle view (see screenshot below) with a different view when the user clicks on the button.
This is the simple view I want to load into the middle view:
And this is the source code of the ViewController:
ViewController.h
#import
#interface ViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIButton *loadxibButton;
#property (strong, nonatomic) IBOutlet UIView *middleView;
- (IBAction)buttonClicked:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction)buttonClicked:(id)sender {
NSLog(#"click...");
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:#"NewMiddleContent" owner:self options:nil];
UIView *nibView = [nibObjects objectAtIndex:0];
self.middleView= nibView;
}
#end
When I click on the button, nothing happens, i.e. the new view will not be displayed. Can anybody please help?
Thanks a lot
Christian
Phillip, thanks a lot!
Instead of
- (IBAction)buttonClicked:(id)sender {
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:#"NewMiddleContent" owner:self options:nil];
UIView *nibView = [nibObjects objectAtIndex:0];
self.middleView= nibView;
}
I now use this code:
- (IBAction)buttonClicked:(id)sender {
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:#"NewMiddleContent" owner:self options:nil];
UIView *nibView = [nibObjects objectAtIndex:0];
nibView.frame = CGRectMake(261, 0, 532, 748);
[[[self view] viewWithTag:2] removeFromSuperview];
[[self view] addSubview:nibView];
}
Is this want you meant, i.e. is this like "best practice"?
Bye
Christian
Your view controller has a view property which, presumably, has three subviews (left, middle, and right). Instead of just setting a middleView property in your controller, your strategy should be to update the primary view's subviews array (removing the one that's to be replaced and inserting the new one).
I am fairly new to XCode - I'm designing an app with a single view that just displays a UIWebView that loads my jQuery mobile web site.
I have the Default.png and Default#2x.png files for the Launch images in place. When I run the app on my test device or in the emulator, it shows my Launch Image, and then flashes a white screen while the UIWebView loads the first page.
I know that I can change the background color and opacity so it will flash a different color than white, but I would like to prevent the flash altogether. I would like the app to launch, show the Launch image, and not show the UIWebView until the first page has completely loaded. Help?
# Andreas Volz (and anyone else wondering how I solved the problem of the white "flash")
First, add the name-of-loading-image.png and name-of-loading-image#2x.png files to your Xcode project. The regular image should be 320 x 460, and the #2x image should be 640 x 920.
Then, in my ViewController.h file I added these properties:
#property (nonatomic, retain) UIWebView *webView;
#property(nonatomic, strong) UIImageView *loadingImageView;
#end
And then in my ViewController.m file I added this:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController;
#synthesize webView;
#synthesize loadingImageView;
- (void)viewDidLoad
{
[super viewDidLoad];
//**************** Set website URL for UIWebView
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.example.com"] cachePolicy:NSURLCacheStorageAllowed timeoutInterval:20.0]];
//**************** Add Static loading image to prevent white "flash" ****************/
UIImage *loadingImage = [UIImage imageNamed:#"name-of-loading-image.png"];
loadingImageView = [[UIImageView alloc] initWithImage:loadingImage];
loadingImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"name-of-loading-image.png"],
nil];
[self.view addSubview:loadingImageView];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
// Remove loading image from view
[loadingImageView removeFromSuperview];
}
To know when your webView has finished loading, you must implement the UIWebViewDelegate protocol.
In your viewController's .h file:
#interface viewController : UIViewController <UIWebViewDelegate>
{
UIWebView *webView;
}
#end
Then in your viewController's .m file, add this method:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(#"content loading finished");
// Display your webView
[self.view addSubview:webView];
}
You can use the -viewDidLoad method in your viewController's .m to continue displaying your launch image. You can also begin the loading of content for your webView:
- (void)viewDidLoad {
[super viewDidLoad];
// continue to display launch image
UIImage *launchImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"launchImage.png" ofType:nil ]];
UIImageView *launchImageView = [[[UIImageView alloc] initWithImage:launchImage] autorelease];
[self.view addSubview:launchImageView];
// now setup the base view for the webView controller
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor blueColor];
// for rotation
contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.view = contentView;
//create a frame to size and place the web view
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
UIWebView *aWebView = [[UIWebView alloc] initWithFrame:webFrame];
self.webView = aWebView;
//aWebView.scalesPageToFit = YES;
aWebView.autoresizesSubviews = YES;
aWebView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
//set the web view delegates for the web view to be itself
[aWebView setDelegate:self];
//determine the path the to the index.html file in the Resources directory
NSURL *url = [[NSBundle mainBundle] URLForResource:#"index" withExtension:#"html"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[aWebView loadRequest:requestObj];
}
I have a view controller that has a UIWebView object within it.
I would like to load and display a PDF from the internet within the UIWebView.
I have the code working to display the a PDF loaded from the resource bundle, but i am lost on having the PDF loaded from the internet.
I was thinking it would be as simple as changing the fileURLWithPath to point to the location on the internet... although the form displays, it does not show the contents. So I am assuming that I have the wrong URL in the string???
Does anyone have a code snippet to load and display a PDF from the internet within a UIWebView that they would be willing to share???
thanks
tony
I take it you are looking at iOS stuff, not Mac. On iOS, it should really be just as simple as
NSURL* url = [NSURL URLWithString:stringURL];
[aWebView loadRequest:[NSURLRequest requestWithURL:url]];
Use the following for xCode 5.
Interface section - myWebView is the outlet to the UIWebView in my storyboard.
#property (weak, nonatomic) IBOutlet UIWebView *myWebView;
#property NSURL *url;
The rest goes into viewDidLoad section of the ViewController class.
- (void)viewDidLoad
{
[super viewDidLoad];
_url = [[NSURL alloc] init];
_url = [NSURL URLWithString:#"http://deimos3.apple.com/WebObjects/Core.woa/FeedEnclosure/utah.edu.1668842900.01668842919.1681195338/enclosure.pdf"];
[_myWebView loadRequest:[NSURLRequest requestWithURL: _url]];
}
This worked for me but there maybe a more efficient way of doing this.
Here is how i implemented it....
visitNoteViewController *controller = [[visitNoteViewController alloc] initWithNibName:#"visitNoteView" bundle:nil];
NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
controller.pdfUrl = [NSURL URLWithString:#"http://deimos3.apple.com/WebObjects/Core.woa/FeedEnclosure/utah.edu.1668842900.01668842919.1681195338/enclosure.pdf"];
[self presentModalViewController:controller animated:YES];
[controller release];
got it working.