Tumgik
#uirefreshcontrol
yogeshpatelios · 4 years
Video
youtube
iOS Swift 5 Tutorial 2020: Pull to Refresh to a UITableView in iOS Hindi...
0 notes
knowledgewiki · 5 years
Text
Why do not working UIRefreshControl in Swift?
I use the refresh function in WKWebview. The function is normal when performing a refresh. But when I load another html file and come back, it is not refreshed.
@IBOutlet var myWebView: WKWebView! var refController:UIRefreshControl = UIRefreshControl() override func viewDidLoad() { super.viewDidLoad() myWebView.uiDelegate = self myWebView.navigationDelegate = self myWebView.scrollView.delegate = self refController.bounds = CGRect.init(x: 0.0, y: 50.0, width: refController.bounds.size.width, height: refController.bounds.size.height) refController.addTarget(self, action: #selector(self.webviewRefresh(refresh:)), for: .valueChanged) myWebView.scrollView.addSubview(refController) ... } @objc func webviewRefresh(refresh:UIRefreshControl){ refController.endRefreshing() myWebView.reload() } extension mainWebViewController: UIScrollViewDelegate{ func scrollViewDidScroll(_ scrollView: UIScrollView) { print("come in ??") if currentHtmlFileName == "Main.html" { scrollView.bounces = (scrollView.contentOffset.y <= 0) } else { scrollView.bounces = false } } }
As you can see from my code, my WKWebview is scrolling, and the function is executed. However, when the function is activated on a different screen and returned, the function is not called, nor is the refresh working.
The steps for reproducing a problem are as follows:
Load the WKwebView page and execute the refresh function.
Scroll to the bottom screen to see if there is a bounce.
If it works normally, go to a different screen. location.href = "./other.html";
Scroll from another screen to the bottom screen to see if there is a bounce.
If there is no bounce normally, please return to the screen. history.back()
And run the refresh function again.
In my case, I have a bounce, but the refresh does not run, and the function is not called.
Has anyone solved the same problem as me? Is this a bug???
1 Answer
I thought a lot about this problem. So my conclusion is history.back() does not change the value of the bounce. Therefore, the bounce value is false.
So I thought I should reinitialize this value. So I added a function in the section that completes page navigation.
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { if currentHtmlFileName == "Main.html" { scrollViewDidScroll(myWebView.scrollView) } }
With this addition, the bounce value was reinitialized, and my refresh worked.
Archive from: https://stackoverflow.com/questions/59028323/why-do-not-working-uirefreshcontrol-in-swift
from https://knowledgewiki.org/why-do-not-working-uirefreshcontrol-in-swift/
0 notes
arthurknopper · 5 years
Text
Pull to Refresh iOS Tutorial
A UIRefreshControl object provides a standard control that can be used to initiate the refreshing of a table view’s contents. When pulled,  a little wheel starts spinning at the top, until the refresh has completed.  At that time, the wheel disappears, and the view bounces back into place. In this tutorial a refresh control will be added to a table view. When the control is pulled the sorting order of the rows will be reversed. This tutorial is made with Xcode 10 and built for iOS 12.
Open Xcode and create a new Single View App.
For product name, use IOSPullToRefreshTutorial and then fill out the Organization Name and Organization Identifier with your customary values. Enter Swift as Language and choose Next.
Go to the storyboard. Remove the View Controller from the Storyboard and drag a Navigation Controller to the Scene. This will also add the Table View Controller. Select the Navigation Controller and go to The Attribute inspector. In the View Controller section check the "Is Initial View Controller" checkbox.
Select the Table View Cell and go to the Attributes Inspector. In the Table View Cell section set the Identifier  to "Cell".
The storyboard will look like this.
Since the View Controller is removed from the Storyboard the ViewController.swift file can also be deleted from the project. Add a new file to the project, select iOS->Source->Cocoa Touch Class. Name it TableViewController and make it a subclass of UITableViewController.
The TableViewController class needs to be linked to The Table View Controller object in the Storyboard. Select it and go the Identity Inspector. In the Custom Class section change the class to TableViewController.
Go to TableViewController.swift and create a property containing an array of the first letters of the alphabet.
var alphabet = ["A","B","C","D","E","F","G","H","I"]
The TableViewController class contains some boilerplate code. Change the following delegate methods
override func numberOfSections(in tableView: UITableView) -> Int { // 1 return 1 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // 2 return alphabet.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // 3 let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) cell.textLabel?.text = alphabet[indexPath.row] return cell }
There is only one section in the Table View so 1 needs to be returned in the numberOfSections(in:) method.
The number of rows is equal to the number of items in the array so the count property of the array class is used.
The letter of the alphabet at the current index of the apps array is assigned to the text property of the textLabel property of the current cell.
Build and Run the project.
Now that some rows are filled let's get going with the refresh control. If the pull to refresh is initiated the rows sort in descending/ascending order. First a Boolean is needed to switch the sort order. Add the following property in the interface section.
var isAscending = true
Change the viewDidLoad method.
override func viewDidLoad() { super.viewDidLoad() let refreshControl = UIRefreshControl() refreshControl.addTarget(self, action: #selector(sortArray), for: .valueChanged) self.refreshControl = refreshControl }
Every time the refresh control is pulled the UIControlEvent.ValueChanged event is triggered, which will call the sortArray method. Let's implement this method.
@objc func sortArray() { let sortedAlphabet = alphabet.reversed() for (index, element) in sortedAlphabet.enumerated() { alphabet[index] = element } tableView.reloadData() refreshControl?.endRefreshing() }
First the array is reversed with the reverse function. Then enumerate through the reversed array will be enumerated, where the reversed array will be loaded into the original alphabet array. The Table View is reloaded to update the contents and the RefreshControl animation is ended.
Build and Run, Pull-refresh a few times and the sorting order of the rows in the table view will be reversed.
You can download the source code of the IOSPullToRefreshTutorial at the ioscreator repository on Github
0 notes
iyarpage · 7 years
Text
Top 10 Libraries for iOS Developers
Update note: This tutorial has been updated by Kishin Manglani. The original tutorial was written by Marcelo Fabri.
It’s no secret that third-party iOS developer libraries can save precious time when you’re doing developing apps. The iOS open-source community is quite active, and we all know that leveraging libraries is a must when developing an app on your own. Each library offers different tools that you can use to enhance your next iPhone app, including working around some of the most obnoxious constraints of Swift and Objective-C.
Selection Criteria
Rating iOS developer libraries is a rather subjective proposition. What makes one library “better” than the next? When libraries solve such a vast range of problems and no two are alike, it’s difficult to make logical comparisons and rank them in order of best to worst.
Fortunately, CocoaPods, a popular Swift and Objective-C dependency manager, collects anonymous stats when users install packages. I scraped its statistics site to find out which open-source packages are most popular right now, rather than polling my colleagues or trying to rate them for myself, and below are the results!
1. AFNetworking
AFNetworking is an Objective-C networking library for iOS, macOS and tvOS. It is a robust library that has been around for many years. From basic networking to advanced features such as Network Reachability and SSL Pinning, AFNetworking has it all. It is one of the most popular iOS libraries of all time with almost 50 million downloads.
AFNetworking: http://ift.tt/xQh6e6
2. SDWebImage
SDWebImage is an asynchronous image downloader with caching. It has handy UIKit categories to do things such as set a UIImageView image to an URL. While networking has become a little bit easier in Cocoa over the years, the basic task of setting an image view to an image using an URL hasn’t improved much. SDWebImage helps ease a lot of pain, so that’s why it’s so popular with iOS app developers.
SDWebImage: http://ift.tt/Hf9tea
3. Alamofire
Alamofire is AFNetworking’s successor but is written in Swift. You might be wondering why there are two different networking libraries in the upper echelon of this list, but I assume it’s due to the fact that networking libraries are just extremely useful for iOS app development. The two libraries share a similar feature set, with the main difference being the language in which they are written.
If you are starting a brand new Swift project, my recommendation is to use Alamofire so that your core networking library is consistent with your own source code. Otherwise, both AFNetworking and Alamofire are great options.
Alamofire: http://ift.tt/1ABz8c0
4. MBProgressHUD
MBProgressHUD is another useful library that fills a big hole in UIKit. This popular iOS developer library provides a class that displays a heads-up display (HUD) with a spinner, text, or images to show loading, progress, success/failure, or any other alerts to the user. Since iOS has long lacked a native HUD component, I don’t need to tell you how helpful such features are!
MBProgressHUD: http://ift.tt/qVAFSc
5. Masonry
Masonry is a lightweight framework that makes wrestling with AutoLayout much less strenuous through simpler syntax. It provides its own chainable DSL that makes AutoLayout code more concise and readable. It also provides several helper methods for common layouts that will shorten over a dozen lines of code with AutoLayout to a single line. For example, if you want to set the edges of a UITableView to the edges of its superview, you can use this: make.edges.equalTo(self);
Masonry: http://ift.tt/1JMLpgH
6. SwiftyJSON
SwiftyJSON improves your life when it comes to handling JSON in Swift. Parsing JSON with Swift can be tricky due to type casting issues that make it difficult to deserialize model object, amd it may require a bunch of nested if statements. SwiftyJSON makes all of it quite simple to do. It’s also the second-most popular Swift library.
SwiftyJSON: http://ift.tt/Z2t6lA
7. SVProgressHUD
SVProgressHud is another HUD library for iOS and tvOS. The API is a bit simpler than MBProgressHUD because it creates a singleton, so you just need to call show and hide when using it. You can also customize the HUD with text, an image, or a progress indicator. Again, there is definitely a need for this when developing apps, and it is a useful alternative to MBProgressHUD.
SVProgressHUD: http://ift.tt/1Q27fRk
8. MJRefresh
MJRefresh offers you an easy way to add pull-to-refresh functionality to a UITableView. Unfortunately, the standard UIRefreshControl disappoints when it comes to customization options, so MJRefresh is a great stand-in that allows you to add text, an animation or even a UIView. You can also add pull-to-refresh actions in a block or closure, making it even easier to implement than the native UIActivityIndicatorView.
MJRefresh: http://ift.tt/1FVgXzw
9. CocoaLumberjack
CocoaLumberjack is a simple but powerful logging framework for all your logging needs. If you want to do more than NSLog or print, CocoaLumberjack can help. You can do remote logging, log to a local file, write to multiple loggers, and create different log levels. Ever had to reproduce an elusive bug, or needed to get a better grasp on some user behavior? CocoaLumberjack is very helpful in these cases.
CocoaLumberJack: http://ift.tt/1auCfmI
10. Realm
Realm is an enticing, cross-platform alternative to Core Data when it comes to persistence. It’s easier to work with than Core Data, as well as faster, and you even get a data browser to explore Realm database files. In case you need another reason to love Realm, this popular library for iOS app development recently launched a platform to sync data between apps in real-time.
If you need to do any data persistence, I’d definitely recommend checking out Realm as an alternative to Core Data.
Realm: http://ift.tt/W7Pfhw
We even have a couple of Realm video tutorial series to help you get started with Realm!
Beginning Realm on iOS
Intermediate Realm on iOS
Honorable Mentions
Only two out of the most popular iOS developer libraries are written in Swift! Hard to believe when you’re living, breathing, and eating Swift. Here are a couple of Swift libraries that didn’t quite make the top 10, according to the data I pulled, but are worthy of your attention.
SnapKit
SnapKit is another iOS library that simplifies AutoLayout simpler, and is similar to Masonry (above). In fact, SnapKit is a successor of Masonry that happens to be written in Swift. The authors of the library recommend that if you are starting a Swift project go with SnapKit, but if you are using Objective-C then go with Masonry.
SnapKit: http://ift.tt/1Ghmfc7
Kingfisher
Similar to SDWebImage above, Kingfisher is a library for downloading and caching images that is written purely in Swift. It includes extensions for UIImageView and UIButton, which makes it more obliging. You can also add a placeholder image that should show while the actual image is downloading.
Kingfisher: http://ift.tt/1zbWxhh
Many of the leading iOS libraries continue to be written for Objective-C, but I’m seeing new Swift libraries emerging regularly. Almost daily at times. The trend is shifting toward Swift. You’re seeing so many Objective-C libraries on this list years after Swift’s release because they are tried and true and trusted in tens of thousands of apps.
As we close out 2017, these are the most popular libraries according to the number of installs.
You can pull the data for yourself from this link: http://ift.tt/2jXMC01.
Just swap Alamofire with whatever library you want to query, and remember that it is case-sensitive.
You should have a good idea of the best libraries to make your iOS app development experience a little smoother. Think I missed a great library? Or want to talk about your experiences with these libraries? Let’s talk about it in the forums.
The post Top 10 Libraries for iOS Developers appeared first on Ray Wenderlich.
Top 10 Libraries for iOS Developers published first on http://ift.tt/2fA8nUr
0 notes
anhphuong · 9 years
Link
Hướng dẫn rất chi tiết
0 notes
goodanswerbiz · 9 years
Text
Fixed UIRefreshControl without UITableViewController #dev #it #asnwer
Fixed UIRefreshControl without UITableViewController #dev #it #asnwer
UIRefreshControl without UITableViewController
Just curious, as it doesn’t immediately seem possible, but is there a sneaky way to leverage the new iOS 6 UIRefreshControl class without using a UITableViewController subclass?
I often use a UIViewController with a UITableView subview and conform to UITableViewDataSource and UITableViewDelegate rather than using a UITableViewController outright.
Ans…
View On WordPress
0 notes
sevennet-blog · 10 years
Text
How to: UIRefreshControl without UITableViewController
UIRefreshControl without UITableViewController
Just curious, as it doesn’t immediately seem possible, but is there a sneaky way to leverage the new iOS 6 UIRefreshControl class without using a UITableViewController subclass?
I often use a UIViewController with a UITableView subview and conform to UITableViewDataSource and UITableViewDelegate rather than using a UITableViewController outright.
Ans…
View On WordPress
0 notes
swiftdev · 10 years
Text
UIRefreshControl funkiness
When using a UIRefreshControl on a UIScrollView that is being built with Interface Builder, must remember to set Simulated Metrics Size back to "Inferred" in order to get the UIRefreshControl to start working! 
0 notes
g8production · 10 years
Text
iOS7 and UIRefreshControl in UIViewController (with UITableView)
A UIRefreshControl object provides a standard control that can be used to initiate the refreshing of a table view’s contents. 
If you are into a UITableViewController, you can use the refreshControl property like explained here.
But how can you use it programmatically? How can you change the tintColor? How can you change the attributeTitle color? If you wanna use the UIRefreshControl into a UIViewController that has a UITableView inside... and if you are using iOS7... you can do it writing the code below.
How you can see, the best solution is to put the UIRefreshControl into a UIView, so the UIRefreshControl not goes under the top bar.
@interface MyViewController () { UIRefreshControl *refreshControl; } @property (weak, nonatomic) IBOutlet UITableView *tableView; @end @implementation MyViewController - (void)viewDidLoad { [super viewDidLoad]; UIView *refreshView = [[UIView alloc] initWithFrame:CGRectMake(0, 55, 0, 0)]; [self.tableView insertSubview:refreshView atIndex:0]; //the tableView is a IBOutlet refreshControl = [[UIRefreshControl alloc] init]; refreshControl.tintColor = [UIColor redColor]; [refreshControl addTarget:self action:@selector(reloadDatas) forControlEvents:UIControlEventValueChanged]; /* NSMutableAttributedString *refreshString = [[NSMutableAttributedString alloc] initWithString:@"Pull To Refresh"]; [refreshString addAttributes:@{NSForegroundColorAttributeName : [UIColor grayColor]} range:NSMakeRange(0, refreshString.length)]; refreshControl.attributedTitle = refreshString; */ [refreshView addSubview:refreshControl]; } -(void)reloadDatas { //update here... [refreshControl endRefreshing]; } @end
That's all.
1 note · View note
hkbenchan · 10 years
Text
UIRefreshControl on iOS7 translucent navigation bar
When using the UIRefreshControl on iOS 7 translucent navigation bar, the refresh spinner is located right under the translucent nav bar.
Possible fix:
First extends UIRefreshControl,
then override the layoutSubView method
- (void)layoutSubviews {
    [super layoutSubviews];
    // getting containing scrollView
    UIScrollView *scrollView = (UIScrollView *)self.superview;
    // saving present top contentInset, because it can be changed by refresh control
    if (!topContentInsetSaved) {
topContentInset = scrollView.contentInset.top;
        topContentInsetSaved = YES;
    }
    // saving own frame, that will be modified
CGRect newFrame = self.frame;
    // if refresh control is fully or partially behind UINavigationBar
if (scrollView.contentOffset.y + topContentInset > -newFrame.size.height) {
        // moving it with the rest of the content
        newFrame.origin.y = -newFrame.size.height;
        // if refresh control fully appeared
    } else {
        // keeping it at the same place
        newFrame.origin.y = scrollView.contentOffset.y + topContentInset;
    }
    // applying new frame to the refresh control
self.frame = newFrame;
}
As well as declare this in the .m file
@implementation MyRefreshControl {
CGFloat topContentInset;
BOOL topContentInsetSaved;
}
Final step, in that table view controller, in the viewDidLoad or somewhere else, put this:
self.refreshControl = [[MyRefreshControl alloc] init]; // create the new instance
[self.refreshControladdTarget:selfaction:@selector(pullToRefresh:) forControlEvents:UIControlEventValueChanged]; // add the event to refresh, like getting data from other sources
self.tableView.contentInset = UIEdgeInsetsMake(20 + 44, self.tableView.contentInset.left, self.tableView.contentInset.bottom, self.tableView.contentInset.right); // 20 for status bar, 44 for navigation bar
// of course need to check if the status bar becomes 44 when phone call comes)
That's it. Hope apple has documented this officially.
Solution credits: Anthony Dmitriyev Sources: http://stackoverflow.com/questions/12913208/uitableview-with-uirefreshcontrol-under-a-semi-transparent-status-bar
0 notes
jaytrixz-dev · 11 years
Text
Quick and Complete UIRefreshControl Tutorial
Check out this link:
http://www.intertech.com/Blog/ios-6-pull-to-refresh-uirefreshcontrol/
This is the how you implement GCD to show the spinner:
- (void)viewDidLoad
{
    [super viewDidLoad];
    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to refresh"];
    [refreshControl addTarget:self action:@selector(refreshing:) forControlEvents:UIControlEventValueChanged];
    self.refreshControl = refreshControl;
}
This is the refreshing method
- (void)refreshing:(UIRefreshControl *)refresh
{
    NSLog(@"Refreshing...");
         refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Refreshing data..."];
    [refresh beginRefreshing];
         dispatch_queue_t queue = dispatch_queue_create("table view loading queue", NULL);
    dispatch_async(queue, ^{
        sleep(5);
                 dispatch_async(dispatch_get_main_queue(), ^{
            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];
        });
    });
}
0 notes
arthurknopper · 7 years
Text
Add Pull to Refresh iOS Tutorial
A UIRefreshControl object provides a standard control that can be used to initiate the refreshing of a table view’s contents. When pulled,  a little wheel starts spinning at the top, until the refresh has completed.  At that time, the wheel disappears, and the view bounces back into place. In this tutorial a refresh control will be added to a table view. When the control is pulled the sorting order of the rows will be reversed. This tutorial is made with Xcode 9 and built for iOS 11.
Open Xcode and create a new Single View App.
For product name, use IOS11PullToRefreshTutorial and then fill out the Organization Name and Organization Identifier with your customary values. Enter Swift as Language and choose Next.
Go to the storyboard. Remove the View Controller from the Storyboard and drag a Navigation Controller to the Scene. This will also add the Table View Controller. Select the Navigation Controller and go to The Attribute inspector. In the View Controller section check the "Is Initial View Controller" checkbox.
Select the Table View Cell and go to the Attributes Inspector. In the Table View Cell section set the Identifier  to "Cell".
The storyboard will look like this.
Since the View Controller is removed from the Storyboard the ViewController.swift file can also be deleted from the project. Add a new file to the project, select iOS->Source->Cocoa Touch Class. Name it TableViewController and make it a subclass of UITableViewController.
The TableViewController class needs to be linked to The Table View Controller object in the Storyboard. Select it and go the Identity Inspector. In the Custom Class section change the class to TableViewController.
Go to TableViewController.swift and create a property containing an array of the first letters of the alphabet.
var alphabet = ["A","B","C","D","E","F","G","H","I"]
The TableViewController class contains some boilerplate code. Change the following delegate methods
override func numberOfSections(in tableView: UITableView) -> Int { // 1 return 1 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // 2 return alphabet.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // 3 let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) cell.textLabel?.text = alphabet[indexPath.row] return cell }
There is only one section in the Table View so 1 needs to be returned  in the numberOfSections(in:) method.
The number of rows is equal to the number of items in the array so the count property of the array class is used.
The letter of the alphabet at the current index of the apps array is assigned to the text property of the textLabel property of the current cell.
Build and Run the project.
Now that some rows are filled let's get going with the refresh control. If the pull to refresh is initiated the rows sort in descending/ascending order. First a Boolean is needed to switch the sort order. Add the following property in the interface section.
var isAscending = true
Change the viewDidLoad method.
override func viewDidLoad() { super.viewDidLoad() let refreshControl = UIRefreshControl() refreshControl.addTarget(self, action: #selector(sortArray), for: UIControlEvents.valueChanged) self.refreshControl = refreshControl }
Every time the refresh control is pulled the UIControlEvent.ValueChanged event is triggered, which will call the sortArray method. Let's implement this method.
@objc func sortArray() { let sortedAlphabet = alphabet.reversed() for (index, element) in sortedAlphabet.enumerated() { alphabet[index] = element } tableView.reloadData() refreshControl?.endRefreshing() }
First the array is reversed with the reverse function. Then enumerate through the reversed array will be enumerated, where the reversed array will be loaded into the original alphabet array. The Table View is reloaded to update the contents and the RefreshControl animation is ended.
Build and Run, Pull-refresh a few times and the sorting order of the rows in the table view will be reversed.
You can download the source code of the IOS11PullToRefreshTutorial at the ioscreator repository on Github
0 notes
firelabi · 12 years
Quote
iOS 6からは、UI KitにUIRefreshControlが追加された。これは、いわゆる「引っ張って更新(Pull to Refresh)」を実現するコントロール
Xcode 4.5がMac App Storeに登場、あとUIRefreshControl « HMDT Blog
0 notes