Adding Pull To Refresh functionality to UITableView - iphone

I have a UIViewCOntroller, and i have added 2 tableviews, and 3 textfields to it. The order of UI view controls are as follows;
1.) tableview - A - present in the first 1/2
2.) textFields
3.) tableVIew - B
I need to add the pullTorefresh functionality to the B tableView, How can i do this. I have tried several libraries (PullToRefresh, EGOTableViewPullRefresh)
Can someone give me sample code which suits my scenario.
Something like this image, (the image shows Sections, but i have done mine using seperate Tableviews, and mine has 3 textfields in between the 2 tableview). I need the 2nd tableview to have the PullToRefresh functionality.
note: Please don't tell me to try PullToRefresh, EGOTableViewPullRefresh and it doesn't address my scenario. But, if you had tried it and if it works please do help me.

iOS 6 added new control - pull-to-refresh control available for UITableViewControllers.
add following code in ViewDidLoad-
- (void)viewDidLoad
{
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:#selector(refresh)
forControlEvents:UIControlEventValueChanged];
[self.tableViewB addSubview:refreshControl];
}
- (void)refresh
{
//write your code here
// for example
[self.tableViewB reloadData];
}
-(void)stopLoading
{
//after completing your action,stop loading now
[refreshControl endRefreshing];
}

Related

Using background view for UITableViewCell in iOS 7 covers default delete button

I am using background view for UITableviewCell which is an imageview, I am using the image view to achieve two side corners for first and last cell. It is working fine But the problem is when I use this background view, the default cell delete button which comes when we press the tableviewcell default edit button is being covered by the background view.If I give clear color for the background view it is working fine but I want background view to be set.
Is there any idea why the delete button is being covered or hidden by cell background view?
It happens in iOS 7
Please help! thanks in advance.
how about instead of using the background view. just use your image as the background patternn color try using this
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:YOUR_IMAGE]];
Had the exact same issue. Solved it by sending the backgroundView to back when transition starts & also again on the next runloop cycle (using dispatch_async).
Here's the code you should add to your cell class .m file (i.e. MyCustomTableCellView.m)
// Fix for iOS7, when backgroundView comes above "delete" button
- (void)willTransitionToState:(UITableViewCellStateMask)state {
[super willTransitionToState:state];
[self sendSubviewToBack:self.backgroundView];
dispatch_async(dispatch_get_main_queue(), ^{
[self sendSubviewToBack:self.backgroundView];
});
}
- (void)didTransitionToState:(UITableViewCellStateMask)state {
[super didTransitionToState:state];
[self sendSubviewToBack:self.backgroundView];
}
I spoke with an Apple UIKit engineer today at the iOS 7 Tech Talks event in SF, and confirmed that this is an open bug that will be fixed "soon" by Apple.
UPDATE 10/22/13: iOS 7.0.3 fixes this issue.
Workaround
I found an answer in the Apple Developer Forums for a workaround. I've built on that to handle both the case for backgroundView and selectedBackgroundView.
I still see this issue in production iOS7.0.2. This workaround however, is simple and fixes the issue (for me). Drop this code into your custom UITableViewCell subclass.
You can also find it at this gist: https://gist.github.com/idStar/7018104
- (void)layoutSubviews {
[super layoutSubviews];
[self applyEditingModeBackgroundViewPositionCorrections];
}
/**
When using a backgroundView or selectedBackgroundView on a custom UITableViewCell
subclass, iOS7 currently
has a bug where tapping the Delete access control reveals the Delete button, only to have
the background cover it up again! Radar 14940393 has been filed for this. Until solved,
use this method in your Table Cell's layoutSubviews
to correct the behavior.
This solution courtesy of cyphers72 on the Apple Developer Forum, who posted the
working solution here: https://devforums.apple.com/message/873484#873484
*/
- (void)applyEditingModeBackgroundViewPositionCorrections {
if (!self.editing) { return; } // BAIL. This fix is not needed.
// Assertion: we are in editing mode.
// Do we have a regular background view?
if (self.backgroundView) {
// YES: So adjust the frame for that:
CGRect backgroundViewFrame = self.backgroundView.frame;
backgroundViewFrame.origin.x = 0;
self.backgroundView.frame = backgroundViewFrame;
}
// Do we have a selected background view?
if (self.selectedBackgroundView) {
// YES: So adjust the frame for that:
CGRect selectedBackgroundViewFrame = self.selectedBackgroundView.frame;
selectedBackgroundViewFrame.origin.x = 0;
self.selectedBackgroundView.frame = selectedBackgroundViewFrame;
}
}
What we're basically doing here, is resetting the x-origin of these background views to zero at table cell layout time, if they are in editing mode. Why they are translated incorrectly, and why they are above the Apple provided 'Delete' button view is presumably, part of the known issue Apple is working to fix.
I was facing the same issue and finally got solution. Try this:
Instead of calling setBackgroundImage in cellForRowAtIndexPath (Delegate Method). Call it in willDisplayCell:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:#"cellList.png"]];
}
Enjoy Coding
Try below code may be help you.
[youttablecell sendSubviewToBack:yourimageview]

Adding a pull to refresh feature to UIWebView iOS

I'm looking to add a Pull to refresh feature to a UIWebView that I have in an app. I've used Pull to refresh in the past on table views, but I'm struggling to find any good tutorials/libraries to help me add it to UIWebViews specifically and this project.
I did get some of the way using PullToRefreshView by chpwn (https://github.com/chpwn/PullToRefreshView) but I can't get it detecting the drag.
Does anyone know a better plug in/library?
For me this post and code worked like a charm
http://sonnyparlin.com/2011/12/pulltorefresh-ios-5-and-arc-tutorial/
I'm new to iOS development, so this may not be the best way… but it worked for me.
I took the controller that was wrapping my WebView and I changed it to a UITableViewController (it was just a UIViewController previously) so that I could take advantage of the refreshControl property of that controller (ios6 and up). I'm not making use of the TableView inside of the UITableViewController (though, it does seem to require one to exist, which I include, but I just don't populate it). I added 2 methods to the controller:
- (void)addPullToRefresh
{
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:#"Pull to Refresh"];
[refreshControl addTarget:self.myWebView action:#selector(reload)
forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
}
- (void)stopRefresh
{
[self.refreshControl endRefreshing];
}
I put a call to [self addPullToRefresh]; in viewDidLoad, and I added a call to [self stopRefresh]; in webViewDidFinishLoad:
I got my instructions for how to use the refreshControl property of UITableViewController here.

How do I launch a modal view from a custom UITabBar?

I've built out the raised-center UITabBar from this GitHub location.
My challenge now is that I can't figure out how to create a modal view that will appear when the button is pressed.
Has anyone used the idev-recipes RaisedCenterTabBar with luck? How did you implement the modal sheet that appears there?
Alternatively, is there a different gitHub project that has a working custom tab bar with a modal sheet?
Thank you!
Here was my solution, it was BY FAR the cleanest way I found to do this... I really hope it helps, I spent hours researching the best ways.
I setup a "UITabBarController" delegate that connects directly to my tab interface built out on my storyboard.
** Don't forget to include the "tabBarController" delegate in your header file
** Notice this callback method is NOT the "didSelectViewController" but rather the "shouldSelectViewController". This method handles the request before the tab is selected and that is exactly what you want so you can STOP the request before it ever happens... This way you don't have to save the current index you are on, pass it around and all that nonsense.
Then I am simply checking what tab WILL be selected (based on the view controller's title.
** Also: this is my code, change it as needed for your code. But the principals should remain. My "performSegueWithIdentifier" is actually a manual segue connected to my tab controller that opens in a modal. This code is working brilliant for me.
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
if([[viewController title] isEqualToString:#"tellvc"])
{
[self performSegueWithIdentifier:#"shareModelViewController" sender:Nil];
return NO;
}
else
{
return YES;
}
}
I have something similar in a program of mine that I'm working on and would be glad to show you how I do it. I have a couple of viewControllers in a TabBar. I create my Plus button in whichever VC I decide will appear first on the screen in ViewDidLoad.
// Create a plus button that appears on the tabBar
UIImage *plusButton = [UIImage imageNamed:#"plusbutton.png"];
UIView *tabBarView = [[self tabBarController] view];
addButton = [UIButton buttonWithType:UIButtonTypeCustom];
[addButton setFrame:CGRectMake(127.0, 432.0, [plusButton size].width, [plusButton size].height)];
[addButton setBackgroundImage:plusButton forState:UIControlStateNormal];
[tabBarView addSubview:addButton];
[addButton addTarget:self action:#selector(scalePicker:) forControlEvents:UIControlEventTouchUpInside];
I make the button a subView of the tabBarController's view. Later on in the implementation of this VC I have a method called scalePicker: which creates and instance of one of my other VC's and presents it modally. Here is the code for that: (note: this is the method that I set as a target for the plus button in the code above)
-(void) scalePicker:(id)sender
{
// create the view scalePicker, set it's title and place it on the top of the view hierarchy
sp = [[ScalePickerVC alloc] init];
[self presentModalViewController:pickerNavController animated:YES];
}
I hope this helps you,
Good Luck!

ABPersonViewController drawn under the navgation bar

The context:
I am working on an app that maintains a list of contacts along with their record IDs for it's own reference.
When the user needs to change the number associated with a specific contact within the app, I am trying to display the ABPersonViewController so the user can choose the new number from the contact in AB.
The problem:
The problem is that the ABPersonViewController that is opened is starting all the way from the top of the screen as if it does not know that there is a navigation bar on the top.
As a result some of the top part of the ABPersonViewController screen (the top part of the person image and the top part of the name) is underneath the navigation bar.
Ideally i want it to look like this, but not in edit mode: http://developer.apple.com/library/ios/documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Art/person_view.jpg
Also I wanted to add a "cancel" button to the top right part of the nav bar. Trying to add that as a bar button is not working either.
The code:
this is how I am adding the ABPersonViewController to the navigationController:
ABPersonViewController *personViewController = [[ABPersonViewController alloc] init];
personViewController.personViewDelegate = self;
personViewController.displayedPerson = person;
[self.m_circleNavController pushViewController:personViewController animated:YES];
[personViewController release];
The self here is a UIVIewController.
The m_circleNavController is the UINavigationController to which the UIVIewController belongs.
I tried these 2 ways of showing the person view, but both behave the same way.
[self.m_circleNavController pushViewController:personViewController animated:YES];
[self.navigationController pushViewController:personViewController animated:YES];
I'm not too sure what I am doing wrong, or what is the best way to do it.
I tried a lot of different ways to display it in vain.
The viewcontroller was behaving as though it was starting about 40 pixels above the top edge of the screen.
I was able to fix it in a very weird way finally. In the init function of the viewcontroller I added the following line:
self.view.bounds = CGRectMake(0, -43, 320, 440);
But still no clue as to why it happens this way. I was to close to the deadline to look for a decent solution.
Hello I've been having the same problem as of the new iOS. When this happens on my custom view controllers I have been able to correct it with:
if (self.interfaceOrientation != UIInterfaceOrientationPortrait) { // UI is in landscape position
[self.tableView setContentInset:UIEdgeInsetsMake(32,0,0,0)];
} else { // UI is in portrait position
[self.tableView setContentInset:UIEdgeInsetsMake(44,0,0,0)];
}
But when using the ABPersonViewController I don't quite know how to handle this problem.
Hope someone has an idea...

ViewController displaced vertically by 20px after modal is dismissed: iOS4 Only. Example code included

I hope someone can help... This issue has been discussed here and I have tried the solutions suggested but to no avail.
My problem is best illustrated using the example project which can be downloaded from this URL:
http://www.hitsalive.com/tmp/VCTest.zip
In the example project I have a main UIViewController with two buttons used to call two other UIViewControllers - one using presentModalViewController and the other using "addSubView" (using the AppDelegate). Individually both buttons and UIViewControllers work fine.
However, if I first call the modal viewcontroller, then dismiss it (using dismissModalViewControllerAnimated: YES) and then display the second (addSubView) UIViewController, then all elements and subviews in the second UIViewController (such as the button in the example) get displaced downwards vertically by 20 pixels. And the displacement happens with a momentary delay.
This issue does not happen with SDK 3.2 and below -- just iOS4.
Any help would be appreciated, especially with reference to the example project above.
add [aViewControllerTwo setWantsFullScreenLayout:YES]; to your - (void)flipToViewControllerTwo after ViewControllerTwo *aViewControllerTwo = [[ViewControllerTwo alloc] initWithNibName:#"ViewControllerTwo" bundle:[NSBundle mainBundle]];
In order to solve this you need to do the following with the view controller that appears shifted: add a frame, then set the position of this frame appropriately. Set this frame to the view of the ViewController.
shiftedViewController* ShiftedViewController = [[ShiftedViewController alloc] init ];
CGRect theFrame = [shiftedViewController.view frame];
theFrame.origin.y = 20;
theFrame.origin.x=0;
[shiftedViewController.view setFrame: theFrame];
[self presentModalViewController:shiftedViewController
animated:YES];