I'm using FusionCharts on an iOS application.
Currently I have a view controller with two different UIWebViews that are loading two different charts from different html files.
The problem is that both charts are rendered but one of them is invisible as you can see in the screenshot.
It only works with one chart at a time. How can I fix this?!
screenshot
The problem this issue is is with UIWebView it self for clear explanation check out below link
http://double-slash.net/2010/10/18/using-multiple-ios-uiwebview-objects/ It can be fixed in two way by adopting a spin lock mechanism or increasing rendering time of run loop by customize the UIWebview.
enter code here
#interface FCXTCustomWebView ()
#property (assign) id idelegate;
#end
#implementation FCXTCustomWebView
- (id)init
{
self = [super init];
if (self)
{
self.delegate = self;
}
return self;
}
- (id) initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
self.delegate = self;
}
return self;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.delegate = self;
}
return self;
}
- (void)setDelegate:(id<UIWebViewDelegate>)delegate
{
_idelegate = delegate;
}
- (void)stopRunLoop
{
CFRunLoopRef runLoop = [[NSRunLoop currentRunLoop] getCFRunLoop];
CFRunLoopStop(runLoop);
}
- (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[self performSelector:#selector(stopRunLoop) withObject:nil afterDelay:.01];
if ([_idelegate respondsToSelector:#selector(webView:didFailLoadWithError:)])
{
[_idelegate webView:webView didFailLoadWithError:error];
}
}
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if ([_idelegate respondsToSelector:#selector(webView:shouldStartLoadWithRequest:navigationType:)])
{
return [_idelegate webView:webView shouldStartLoadWithRequest:request navigationType:navigationType];
}
else
{
return YES;
}
}
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
[self performSelector:#selector(stopRunLoop) withObject:nil afterDelay:.01];
if ([_idelegate respondsToSelector:#selector(webViewDidFinishLoad:)])
{
[_idelegate webViewDidFinishLoad:webView];
}
}
- (void) webViewDidStartLoad:(UIWebView *)webView
{
[self performSelector:#selector(stopRunLoop) withObject:nil afterDelay:.1];
if ([_idelegate respondsToSelector:#selector(stopRunLoop)])
{
[_idelegate webViewDidStartLoad:webView];
}
}
- (void) loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
{
[super loadHTMLString:string baseURL:baseURL];
CFRunLoopRunInMode((CFStringRef)NSDefaultRunLoopMode, 1.5, NO);
}
#end
This reply might be too late. I encountered the same issue with HighCharts.
You need not subclass UIWebView. You need to have different Javascript files for the each graph. That would work.
Related
here is the custom collection view,and below label is the (rating view i design).
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initGrayStarView];
[self initYellowStarView];
[self initRatingLabel];
}
return self;
}
but i find that it every time the rating view didn't appear(image view and label did). then i found it's because that i didn't call the init method for rating view,so it's nil ,but why?
this is the init method.
but it never call it ,it only call the layoutSubview method.
Consider this sort of pattern...
-(id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self _setup];
}
return self;
}
-(id)initWithCoder:(NSCoder *)aCoder {
if (self = [super initWithCoder:aCoder]) {
[self _setup];
}
return self;
}
-(void)_setup {
blah;
blah;
blah;
}
Try to "know what is happening" but that will get you through if you're just getting started. Hope it helps
It is in the awakeFromNib: method. Override it in your implementation file like this:
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
[self setupStuff];
}
I have two View Controllers. In the first one i have a button and when you click it you need to display a Web Page in a second View Controller. When I click the button, I see only a black screen.
Here is TabulkaViewController.m code:
#import "TabulkaViewController.h"
#import "WebViewController.h"
#interface TabulkaViewController ()
#end
#implementation TabulkaViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_hbutton.layer.borderWidth = 1;
_hbutton.layer.borderColor = [[UIColor grayColor] CGColor];
}
- (IBAction)hbutton:(id)sender
{
NSURL *url = [NSURL URLWithString:#"http://apple.com"];
WebViewController *webViewController = [[WebViewController alloc] initWithURL:url andTitle:#"Apple"];
[self presentViewController:webViewController animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
Here is code of WebViewController.h:
#import <UIKit/UIKit.h>
#interface WebViewController : UIViewController <UIWebViewDelegate>
{
NSURL *theURL;
NSString *theTitle;
IBOutlet UIWebView *webView;
IBOutlet UINavigationItem *webTitle;
}
- (id)initWithURL:(NSURL *)url;
- (id)initWithURL:(NSURL *)url andTitle:(NSString *)string;
- (IBAction) done:(id)sender;
#end
And here is code of WebViewController.m:
#import "WebViewController.h"
#interface WebViewController ()
#end
#implementation WebViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
webTitle.title = theTitle;
NSURLRequest *requestObject = [NSURLRequest requestWithURL:theURL];
[webView loadRequest:requestObject];}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (id)initWithURL:(NSURL *)url andTitle:(NSString *)string {
if( self = [super init] ) {
theURL = url;
theTitle = string;
}
return self;
}
-(id)initWithURL:(NSURL *)url {
return [self initWithURL:url andTitle:nil];
}
- (IBAction) done:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
webView.delegate = nil;
[webView stopLoading];
}
-(void)webViewDidStartLoad:(UIWebView *)webView
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
You need to instantiate the webView at some point. I suggest you change your viewDidLoad to this:
- (void)viewDidLoad
{
[super viewDidLoad];
webView = [[UIWebView alloc] init];
webTitle.title = theTitle;
NSURLRequest *requestObject = [NSURLRequest requestWithURL:theURL];
[webView loadRequest:requestObject];
}
Since your webView is nullat the start of the method, it needs to be created before you can load any Requests. Just declaring it in the header file is not enough, thats why you need webView = [[UIWebView alloc] init];.
EDIT:
Of course, you could also put that line into your ìnitWithURL:andTitle: method, where the other instantiations take place.
Hi I was trying some examples and checking documentation but I can't get this to work.
Here's my code:
#interface AHMSoudView : UIView <UIInputViewAudioFeedback>
- (void) playClick;
#end
#implementation AHMSoudView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (BOOL) enableInputClicksWhenVisible {
return YES;
}
- (void) playClick {
[[UIDevice currentDevice] playInputClick];
}
#end
In the storyboard I have the view set to my AHMSoundView. In the controller I then have:
- (IBAction)keypadTouchDown:(id)sender {
[((AHMSoudView *)self.view) playClick];
}
But nothing happens. What am I doing wrong?
I have added UINavigationBar in appDelegate method. Please check my atatched screen shots. In bottom is i have used UINavigationBar. In middel of the page history button is there.
Here when i click the history button its cant go to historyviwcontrooler. Because i cant push the view. Can you please tell me how i can push here. When i click history its called only one calls after only thet called another class there only i given UI. How i handel here . please help me
#import "UICallButton.h"
#import "LinphoneManager.h"
#import <CoreTelephony/CTCallCenter.h>
#implementation UICallButton
#synthesize addressField;
#pragma mark - Lifecycle Functions
- (void)initUICallButton {
[self addTarget:self action:#selector(touchUp:) forControlEvents:UIControlEventTouchUpInside];
}
- (id)init {
self = [super init];
if (self) {
[self initUICallButton];
}
return self;
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initUICallButton];
}
return self;
}
- (id)initWithCoder:(NSCoder *)decoder {
self = [super initWithCoder:decoder];
if (self) {
[self initUICallButton];
}
return self;
}
- (void)dealloc {
[addressField release];
[super dealloc];
}
#pragma mark -
- (void)touchUp:(id) sender {
NSString *address = [addressField text];
NSString *displayName = nil;
ABRecordRef contact = [[[LinphoneManager instance] fastAddressBook] getContact:address];
if(contact) {
displayName = [FastAddressBook getContactDisplayName:contact];
}
[[LinphoneManager instance] call:address displayName:displayName transfer:FALSE];
}
#end
Basically, you must have a UINavigationController, and not just a UINavigationBar, in order to be able to perform a push transition to one UIViewController to another.
I'm not explaining how to do that because it's very basic, you should study and read some books/tutorials before begin a real project.
Here's some links to help you:
A nice tutorial
How to use navigation controllers (from apple)
Navigation Controller class reference
I have a UIWebView that uses a ATM HUD while the web page is loading. I can get the HUD to start working, but after the web page loads, it stays there. I need to find a way to get the HUD to stop spinning once loaded. Below is the code I have so far..
#implementation ThenewsViewController
#synthesize hud;
- (void)showHud {
// Show hud with activity indicator
NSLog(#"hud: %#", hud);
if (!hud) {
hud = [[ATMHud alloc] initWithDelegate:self];
[self.navigationController.view addSubview:hud.view];
[hud setCaption:#"Loading news..."];
[hud setActivity:YES];
[hud update];
if (![hud isBeingPresented])
[hud show];
} else {
NSLog(#"hud exists... resetting.");
hud = nil;
[self showHud];
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *myURL = [NSURL URLWithString:#"http://www.hiphopdx.com/m/index.php?s=news"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
[myWebView loadRequest:myRequest];
UIColor *navBarColor = UIColorFromRGB(0x089932);
[[self.navigationController navigationBar] setTintColor:navBarColor];
if (![hud isBeingPresented])
[self showHud];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewDidFinishLoad:(UIWebView *)webView
{
NSLog(#"Done loading web view");
[hud hide];
}
#end
How about this?
ATMHud *blargh;
if(loaded)
{
blargh.hidden = YES;
}
Try this:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
// stop animating here
}
also
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
// stop animating here also
}
Also make sure your "myWebView" instance delegate is set.
F.e _myWebView.delegate = self;