Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 23    Views: 488

LeonG
Apple Fan
Profile
Posts: 694
Reg: Nov 08, 2011
Hamburg
17,740
01/14/14 06:14 AM (11 years ago)

Pull to refresh

Found some tutorials for the pull to refresh method for IOS 6.0 and above. I am not good enough to understand where to put the code, but maybe it is not too hard for one of our Code Gurus? http://www.intertech.com/Blog/ios-6-pull-to-refresh-uirefreshcontrol/ I would like to add this to my Custom URL screens. Maybe someone could explain where to put what to make this work for the BT plugins.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
01/14/14 06:29 AM (11 years ago)
I can't say if it will work or not; I haven't tested it. You would want to alter your BT_screen_customURL.m file. "Step 1" is a method on it's own. copy paste the entire thing outside of any other method in your BT_screen_customURL.m file. "Step 2-3-4" should go in the BT_screen_customURL.m file's 'viewDidLoad' method, usually located towards the top of the plugin; the first or second method listed, typically (although not always) You may (or may not) need additional edits to get this to work, but that's where it goes. Cheers! -- Smug
 
LeonG
Apple Fan
Profile
Posts: 694
Reg: Nov 08, 2011
Hamburg
17,740
like
01/14/14 06:51 AM (11 years ago)
Following error if I copy where you said under the viewdidload part: "Property 'refreshControl' not found on object of type 'BT_screen_customURL"
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
01/14/14 07:05 AM (11 years ago)
looks like a syntax error. Not yours; theirs. I 'suspect' the line causing the error is: self.refreshControl = refresh; try changing: UIRefreshControl *refresh = [[UIRefreshControl alloc] init]; to this: UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; and see if that makes a difference. They're declaring it as one value, and calling it with another (that doesn't exist). Anyway, try it. Cheers! -- Smug
 
LeonG
Apple Fan
Profile
Posts: 694
Reg: Nov 08, 2011
Hamburg
17,740
like
01/14/14 07:11 AM (11 years ago)
That brings us to 4 errors ;-) Initial error stays the same and 3 further errors are called: Use of undeclared identifier 'refresh' Really appreciate you trying to help me out. Think it would be a fantastic feature for all of us if it works!
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
01/14/14 07:19 AM (11 years ago)
Before we get too far into this, what info are you trying to refresh…? Consider this: It's a custom URL, which means it's a web page. The code we're inserting is a refresh of the 'plugin', but not necessarily the content of the plugin. If you just want to reload the webpage, why not use a context menu with a link to the same customURL page, and call it 'refresh'…? Cheers! -- Smug
 
LeonG
Apple Fan
Profile
Posts: 694
Reg: Nov 08, 2011
Hamburg
17,740
like
01/14/14 07:27 AM (11 years ago)
I am refreshing it with the bottom toolbar at the moment and don't like the look of it. For sure a right navbar button would be an option but the pull to refresh function is known by most users now and looks very pretty and even more important: professional! Oh and yes, I need it to refresh the content ; A simple .php script I wrote that gets the input from a sql database. Bottom refresh button does the job, just doesn't look nice.
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
01/14/14 07:49 AM (11 years ago)
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
01/14/14 07:58 AM (11 years ago)
Well in that case, I'd try to do this: figure out what the errors in this code is, and squelch them. In line 5 of the steps 2-4 image of the above link, I'd change: action:@selector(refreshView:) to: action:@selector(refreshData:) which is the refresh method for the button you don't like. this will keep it simple while giving you the behavior you want. It's after midnight here, so I'm gone for the day. Good luck and I'll check back tomorrow. Cheers! -- Smug
 
LeonG
Apple Fan
Profile
Posts: 694
Reg: Nov 08, 2011
Hamburg
17,740
like
01/14/14 08:24 AM (11 years ago)
OK well will keep trying, but looking forward to you coming back to this, as I will probably not solve it.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
01/14/14 09:01 AM (11 years ago)
shameless plug I'm away from my mac, but if you check out my super cool pop up webview I added that feature especially to save button space. It's literally only 3 lines of code
 
LeonG
Apple Fan
Profile
Posts: 694
Reg: Nov 08, 2011
Hamburg
17,740
like
01/14/14 09:09 AM (11 years ago)
Well I have your plugin Kittsy (as all of them) so will have a look right away!
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
01/14/14 09:11 AM (11 years ago)
search for uirefreshcontrol alot of that plugins code has been lifted from the custom url screen. It will be sourounded in if statements as obviously it will only pull to refresh if the webview can scroll and bounce
 
LeonG
Apple Fan
Profile
Posts: 694
Reg: Nov 08, 2011
Hamburg
17,740
like
01/14/14 09:17 AM (11 years ago)
So you got 2 parts of code in your AK:MDBrowser.m file: 1st part: if ([[BT_strings getStyleValueForScreen:appDelegate.rootApp.currentScreenData nameOfProperty:@"allowPullRefresh" defaultValue:@"1"]isEqualToString:@"1"]) { UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; [refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged]; [browser.scrollView addSubview:refreshControl]; } 2nd part: -(void)handleRefresh:(UIRefreshControl *)refresh { [BT_debugger showIt:self theMessage:@"refresh"]; montesino_appDelegate *appDelegate = (montesino_appDelegate *)[[UIApplication sharedApplication] delegate]; //refresh original page or starting file? if([browser canGoBack]){ [browser reload]; }else{ NSURL *remoteURL = [NSURL URLWithString:[BT_strings getStyleValueForScreen:appDelegate.rootApp.currentScreenData nameOfProperty:@"itemNickname" defaultValue:@"http://www.google.co.uk"]]; NSURLRequest *URLReq = [NSURLRequest requestWithURL:remoteURL]; [browser loadRequest:URLReq]; } [refresh endRefreshing]; } So where to put what? I assume the date of last refresh is not displayed as in the other code I posted? Is it difficult to add that?
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
01/14/14 03:06 PM (11 years ago)
With your tutorial its this //view will appear -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [BT_debugger showIt:self theMessage:@"viewWillAppear"]; //load url if(didInit == 0){ didInit = 1; [self initLoad]; } //show adView? if([[BT_strings getJsonPropertyValue:self.screenData.jsonVars nameOfProperty:@"includeAds" defaultValue:@"0"] isEqualToString:@"1"]){ [self showHideAdView]; } //add code below UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; [refreshControl addTarget:self action:@selector(refreshView:) forControlEvents:UIControlEventValueChanged]; refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Refreshing data..."]; [webView.scrollView addSubview:refreshControl]; } //This method below is new -(void)refreshView:(UIRefreshControl *)refresh { refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Refreshing data..."]; if([webView canGoBack]){ [webView reload]; }else{ [self initLoad]; } NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"MMM d, h:mm a"]; NSString *lastUpdated = [NSString stringWithFormat:@"Last updated on %@",[formatter stringFromDate:[NSDate date]]]; refresh.attributedTitle = [[NSAttributedString alloc] initWithString:lastUpdated]; [refresh endRefreshing]; }
 
LeonG
Apple Fan
Profile
Posts: 694
Reg: Nov 08, 2011
Hamburg
17,740
like
01/14/14 03:18 PM (11 years ago)
Wow, thx a lot again Kittsy and Smug, you guys just rock! Only thing it does not show is the cool pull down graphic ; Instead it is a circle that closes the more you pull down. Ok for me, but possible to have the pull down graphic like in the tutorial too?
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
01/14/14 03:22 PM (11 years ago)
That pull down graphic is ios 6 and below check in simulator in ios 7 it's not the stretchy one
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
01/14/14 03:22 PM (11 years ago)
Ios 6 in the tutorial I mean
 
LeonG
Apple Fan
Profile
Posts: 694
Reg: Nov 08, 2011
Hamburg
17,740
like
01/14/14 03:26 PM (11 years ago)
got it! kinda sad, as thee stretchy one is much nicer ;-) I noticed that if I pull down a bit further then needed I can see the spinning wheel and update status text twice, sometimes 3 times. Bug?
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
01/14/14 03:32 PM (11 years ago)
Move this to the viewdidload method instead UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; [refreshControl addTarget:self action:@selector(refreshView:) forControlEvents:UIControlEventValueChanged]; refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Refreshing data..."]; [webView.scrollView addSubview:refreshControl]; See if that solves it
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
01/14/14 03:32 PM (11 years ago)
At the end of the method
 
LeonG
Apple Fan
Profile
Posts: 694
Reg: Nov 08, 2011
Hamburg
17,740
like
01/14/14 03:46 PM (11 years ago)
hmm, seems I am always too stupid to know where to exactly place the code. Whatever I try I get errors, so maybe a last bit of help? Feeling ashamed to ask.
 
LeonG
Apple Fan
Profile
Posts: 694
Reg: Nov 08, 2011
Hamburg
17,740
like
01/16/14 03:04 AM (11 years ago)
Kittsy, could you tell me where to exactly put the code? Cant get it to work.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
01/16/14 10:47 AM (11 years ago)
The bottom of this method //viewDidLoad -(void)viewDidLoad{ [BT_debugger showIt:self theMessage:@"viewDidLoad"]; [super viewDidLoad]; //init screen properties [self setBrowserToolBar:nil]; self.externalURL = @""; self.didInit = 0; //get the dataURL to load. Remember it in externalURL so we can open native browser to current url... self.dataURL = [BT_strings getJsonPropertyValue:self.screenData.jsonVars nameOfProperty:@"dataURL" defaultValue:@""]; [self setExternalURL:dataURL]; //appDelegate popupwebview_appDelegate *appDelegate = (popupwebview_appDelegate *)[[UIApplication sharedApplication] delegate]; //the height of the webView depends on whether or not we are showing a bottom tool bar. int browserHeight = self.view.bounds.size.height; int browserWidth = self.view.bounds.size.width; int browserTop = UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? 0 : 0; if(![appDelegate.rootDevice isIPad]){ browserTop = UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? 0 : 10; } if([[BT_strings getStyleValueForScreen:self.screenData nameOfProperty:@"navBarStyle" defaultValue:@""] isEqualToString:@"hidden"]){ browserTop = 0; } //get the bottom toolbar (utility may return nil depending on this screens data) browserToolBar = [BT_viewUtilities getWebToolBarForScreen:self theScreenData:[self screenData]]; if(browserToolBar != nil){ browserToolBar.tag = 49; browserHeight = (browserHeight - 44); } //webView self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, browserTop, browserWidth, browserHeight)]; self.webView.delegate = self; self.webView.scalesPageToFit = YES; [self.webView setOpaque:NO]; self.webView.backgroundColor = [UIColor clearColor]; self.webView.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth); //data detector types... if([[BT_strings getStyleValueForScreen:self.screenData nameOfProperty:@"dataDetectorType" defaultValue:@"1"] isEqualToString:@"0"]){ self.webView.dataDetectorTypes = UIDataDetectorTypeNone; }else{ self.webView.dataDetectorTypes = UIDataDetectorTypeAll; } if([[BT_strings getStyleValueForScreen:self.screenData nameOfProperty:@"preventUserInteraction" defaultValue:@""] isEqualToString:@"1"]){ [self.webView setUserInteractionEnabled:FALSE]; } [self.view addSubview:webView]; /* //fix up web-view.. In iOS 3.1 < UIScrollView repors as UIScroller (not sure this changed?). UIScrollView has different methods. */ for(UIView* subView in [self.webView subviews]){ //ios sometimes put's images behind web-views (like shadows)... hide these if([subView isKindOfClass:[UIImageView class]]){ [subView setHidden:YES]; } //ios sometimes puts images behind web-view sub-views (like shadows behind UIScrollViews)..hide these for(UIView* shadowView in [subView subviews]){ if([shadowView isKindOfClass:[UIImageView class]]){ [shadowView setHidden:YES]; } } //UIScrollView *tmp = (UIScrollView *)subView; //enable, disable scrolls to top (disables status bar tap-to-top property) if([subView respondsToSelector:@selector(setScrollsToTop:)]){ //[tmp setScrollsToTop:scrollsToTop]; } //hide vertical scroll bar if([[BT_strings getStyleValueForScreen:self.screenData nameOfProperty:@"hideVerticalScrollBar" defaultValue:@""] isEqualToString:@"1"]){ if([subView respondsToSelector:@selector(setShowsVerticalScrollIndicator:)]){ [(UIScrollView *)subView setShowsVerticalScrollIndicator:FALSE]; } } //hide horizontal scroll bar if([[BT_strings getStyleValueForScreen:self.screenData nameOfProperty:@"hideHorizontalScrollBar" defaultValue:@""] isEqualToString:@"1"]){ if([subView respondsToSelector:@selector(setShowsHorizontalScrollIndicator:)]){ [(UIScrollView *)subView setShowsHorizontalScrollIndicator:FALSE]; } } //scroll bounce.. if([[BT_strings getStyleValueForScreen:self.screenData nameOfProperty:@"preventScrollBounce" defaultValue:@""] isEqualToString:@"1"]){ if([subView respondsToSelector:@selector(setBounces:)]){ [(UIScrollView *)subView setBounces:FALSE]; } } //prevent scrolling in iOS 3.1 < if([[BT_strings getStyleValueForScreen:self.screenData nameOfProperty:@"preventAllScrolling" defaultValue:@""] isEqualToString:@"1"]){ if([subView respondsToSelector:@selector(setScrollEnabled:)]){ [(UIScrollView *)subView setScrollEnabled:FALSE]; } } //prevent scrolling in iOS 3.1 > if([[BT_strings getStyleValueForScreen:self.screenData nameOfProperty:@"preventAllScrolling" defaultValue:@""] isEqualToString:@"1"]){ if([[[self.webView subviews] lastObject] respondsToSelector:@selector(setScrollEnabled:)]){ [[[self.webView subviews] lastObject] setScrollEnabled:NO]; } } }//for each sub-view in UIWebView //add the toolbar if we have one (utility may return nil depending on this screens data) if(browserToolBar != nil){ [self.view addSubview:browserToolBar]; //if we don't have a dataURL, disable possible launch in Safari button if([self.dataURL length] < 3){ for(UIBarButtonItem *button in [browserToolBar items]){ //launch in safari app = 103 (see BT_viewUtilties.m > getWebToolBarForScreen) if([button tag] == 103){ button.enabled = FALSE; } } } } //create adView? if([[BT_strings getJsonPropertyValue:self.screenData.jsonVars nameOfProperty:@"includeAds" defaultValue:@"0"] isEqualToString:@"1"]){ [self createAdBannerView]; } UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; [refreshControl addTarget:self action:@selector(refreshView:) forControlEvents:UIControlEventValueChanged]; refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Refreshing data..."]; [webView.scrollView addSubview:refreshControl]; }
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.