I have a UIRefreshControl connected to a UICollection that is defined this way for pull to refresh:
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:#selector(startRefresh:)
self.collectionView.alwaysBounceVertical = YES;
[self.collectionView addSubview:self.refreshControl];
This works fine. However, whenever I move to a new view by either pushing a new view controller or displaying the sliding sidebar menu, and return to this view, the refresh control starts displaying the image for a control pulled all the way (i.e. it doesn't animate and shows the full circle). However, if I pull down fully and release, the refresh control returns to normal functionality. The control works fine, it just looks funky the first time you pull after navigating elsewhere.
I would love any feedback on what might be going wrong. Thanks!
This is what the image looks like when not working (note I am linking to an online image, this is not from my app so this doesn't show that the collectionview is being pulled down):
Posted solution below worked, but I had to do some extra work to figure out when my top view controller received focus from the sidebar menu that I was using (ECSlidingViewController): Is there a way for the Top View Controller in ECSlidingViewController to know when the sidebar menu has been dismissed?
After completed loading You have to stop the refreshing
[tableView.refreshControl endRefreshing]
Hope its useful for you..:)
I had a slightly different issue but the symptoms were similar. This is what worked for me:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_refreshControl.hidden = YES;
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
if (_refreshControl.isRefreshing) {
[self.collectionView sendSubviewToBack:_refreshControl];
}
}
Related
When i use large titles for the Navigation bar, the added UIRefresh control for the UIScrollView is not triggered when pulled down
{
self.scrollView.refreshControl = [[UIRefreshControl alloc] init];
[self.scrollView bringSubviewToFront:self.scrollView.refreshControl];
// add target
}
When i use normal small titles, it starts working by triggering the event
How to make it work with large titles?
I had the same problem a while ago and for me I could make it work by calling scrollView.refreshControl.didMoveToSuperview() in viewDidAppear.
I have two view controllers. In first view controller, I click a button and a webview loads. Before loading web view, it shows a black screen and it goes immediately and the webviews load. Again, when I go from my webview to another view controller, I see the same black screen comes and goes immediately.
PS : This code is not written by me, and it's a little messy so I am not able to paste code here.
Please let me know if you can think of any proper reasoning why its happening and how can I resolve it?
Is there any way i can check for number of view controllers in the stack? Because sometimes instead of black screen it shows some previously loaded screen
This is the code used to remove all the view controller from stack -
UIViewController *vc = self.presentingViewController;
while (vc.presentingViewController) {
vc = vc.presentingViewController;
}
[vc dismissViewControllerAnimated:YES completion:nil];
But still i can see some random screen from the app, comes up instead of black screen before my webview loads.
Any suggestions are welcomed. Thanks!!
Set in InterfaceBuilder or code white background color for UIWebView.
This code may help you:
- (void)viewDidLoad {
[super viewDidLoad];
webViewInstance.opaque = NO;
webViewInstance.backgroundColor = [UIColor clearColor];
//your remaining code here
}
I am trying to create a user interface enabling users to switch between the keyboard and other menus when using a chat application.
On a click of the textField bar I want to raise either the keyboard or a collection view.
The problem occurs when I click the 'menu' button. I want the textField bar to raise revealing my menu view. Then, on a click on the keyboard button, instantly switch to the keyboard, rather than having it slide up from the bottom. This means I need to have the keyboard already loaded and hidden but in the background of the app.
Currently though the earliest I am managing to assign a variable to the keyboard is in the keyboardDidShow function.
-(void) keyboardDidShow: (NSNotification *) notification {
// Get the window the keyboard is a subview of
_window = [UIApplication sharedApplication].windows.lastObject;
_keyboard = _window.subviews[0];
}
This means that after it has been loaded once I can hide and reveal it, but I don't want it visible when it is loading this first time.
To achieve this using alternate means I have tried adding my extra views as subviews of the UIWindow the keyboard is created in:
[_window addSubview:_menuView];
[_window addSubview:_gamesView];
[_window addSubview:_stickerView];
[self hideSpecificView];
Unfortunately I keep coming across the same problem, until I have loaded the keyboard once it needs to fully load before I can get a pointer to it to hide it.
Here is a picture of my toolBar incase I am not being clear:
On clicking the menu icon or the stickers icon I want the bar to raise with a collection view. If I then click the textfield, with these views visible, I want to hide the visible view to immediately show the keyboard behind.
I have also tried experimenting with keyboardWillShow but as the window hasn't been loaded in front our screen I can't get a pointer to the keyboard to hide it before it loads.
An example of what I am after can be found many chat apps (facebook messenger, LINE, Kakao Talk)
Any help would be greatly appreciated
Although the way I came up with isn't perfect it works almost perfectly so hopefully this might help people in the future. If anyone else has solved it differently please post as it would be interesting to know how you did it.
I started by adding a class variable to a UIWindow in my header file and then setting off a timer to ping just after the keyboard will show method finishes. After this method has finished the keyboard has been created, just, and so I allocate it and hide it.
-(void) keyboardWillShow: (NSNotification *) notification {
// More keyboard code
_window = [UIApplication sharedApplication].windows.lastObject;
[NSTimer scheduledTimerWithTimeInterval:0.01
target:self
selector:#selector(allocateKeyboard)
userInfo:nil
repeats:NO];
}
- (void)allocateKeyboard {
if (!_keyboard) {
_keyboard = _window.subviews[0];
}
_keyboard.hidden = YES;
[self setViewForButtonType];
}
I have already previously added my other views, hidden them and constrained them to the bottom of the main view, this means that when the keyboard rises they do too.
- (void)viewDidLoad {
[self.view addSubview:_menuView];
[self.view addSubview:_gamesView];
[self.view addSubview:_stickerView];
}
...
- (void)hideViews {
_keyboard.hidden = YES;
_menuView.hidden = YES;
_gamesView.hidden = YES;
_stickerView.hidden = YES;
}
When buttons get pressed I simple then unhide the view that I want to see and hide the rest of the views.
When I say that this method doesn't work perfectly it is because if you load view main view and then click a button before the keyboard has loaded for the first time then you get a quick glimpse of the keyboard before the view appears over the top. This though only happens the first time and only if they don't click in the text field first.
Anyway, I found this was the best way of making views look like they are in front of the keyboard. Obviously my code was a lot longer and more complex (too long for here) but this is the gist of the method I used to solve it. Comment if you have any queries and I hope this helps.
Because i have more than one element to display at a given location in a mapview, i'd like to display a WEPopoverController in the MKMapView when a given MKPinAnnotationView has been selected.
Presenting the content, which is a tableview works fine so far. I've subclassed the MKPinAnnotationView and when the annotation view gets clicked, i call my custom presentation method.
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
[view openCustomPopoverInFrame:self.view.frame];
[mapView deselectAnnotation:view.annotation animated:NO];
if (_lastAnnotationView != view) {
[_lastAnnotationView closeCustomPopover];
_lastAnnotationView = view;
}
}
- (void) openCustomPopoverInFrame:(CGRect) frame {
CGRect fromFrame = self.frame; //Pin Annotation View Frame
WEPopoverContentViewController *contentViewController = [[WEPopoverContentViewController alloc] initWithStyle:UITableViewStylePlain];
contentViewController.delegate = self;
WEPopoverController *viewController = [[WEPopoverController alloc] initWithContentViewController:contentViewController];
//[viewController setPassthroughViews:[NSArray arrayWithObjects:contentViewController.view, contentViewController.tableView, nil]];
viewController.delegate = self;
//set the displayed content
....
_myPopoverController = [viewController retain];
[viewController presentPopoverFromRect:fromFrame inView:self.superview permittedArrowDirections:UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown animated:YES];
[contentViewController release];
[viewController release];
}
Also selecting buttons in the tableview cells work find and i get the expected response (the method gets called and the popovercontroller stays on top of the view hierarchy).
My problem is, when i click on the WEPopoverController Content (one of the table view cell, in the center, where no button is located), the tap event gets passed through to the map view and therefore hides the popover controller. What can i do, to prevent passed through tap events?
I tried several solutions e.g. set the passThroughViews and also manipulating the hitTest:withEvent: method in the WETouchableView and always return nil, but that also doesn't help me any further.
Best
Nic
EDIT
I've now debugged the hitTest:withEvent: method in the WETouchableView a little more in dept and it seems, that it always returns an instance of UITableViewCellContentView, which i think should be correct so far.
EDIT
So to be a little bit more clear, i want to display a popover controller and when it gets tapped it should neighter disappear like it is the usual annotation behavior nor the underlying view should get called. It should stay on top of the view and the tap event should get caught by the table view and call the specific method (tableView:didSelectRowAtIndexpath:).
I've looked at this solution aswell, but it seems not to work for me and the underlying view (wich is the map view) gets called.
Ok, what worked for me, was to add a UIButton with a transparent background color as the first subview of the table view cell. All Tap Events on the cell now get caught by the UIButton. Btw all swipe events get caught by the table view, so at least that works fine.
To be honest, this isn't a really nice solution, but it works for me. I'd really appreciate any further suggestions!
Best
Nic
I have this bug that I'm struggling with for a few days now. I basically want to make a profile much like Instagram has.
When you click on one of the first two buttons in the upper "tab bar" the content is displayed in the lower part. The upper part of the screen stays the same. I have some UIViewControllers and some UITableViewController. I have like 5 buttons that are suppose to display the viewcontrollers. My problem is that I can display a tableviewcontroller but if I try to display the second and then go back to the first, for instance, it gets stuck to the last one I displayed. I hope this is clear enough. here is the code for displaying the viewcontroller.
- (IBAction)wallButtonPressed:(id)sender
{
if(!_userWallViewController) {
self.userWallViewController = [[WallViewController alloc] init];
self.userWallViewController.activityFeedTableView.bounds = self.containerView.bounds;
}
[self.currentViewController.view removeFromSuperview];
[self.currentViewController removeFromParentViewController];
self.currentViewController = self.userWallViewController;
self.userWallViewController.searchURLString = [NSString stringWithFormat:#"/event/user/%#", self.userID];
self.userWallViewController.containerView = self.containerView;
[self.containerView addSubview:self.userWallViewController.view];
[self addChildViewController:self.userWallViewController];
[self.userWallViewController.view setNeedsDisplay];
[self.userWallViewController viewWillAppear:YES];
}
containerView is an UIView that takes the whole lower part of the screen. currentViewController is a placeholder viewController and userWallViewController is a UITableViewController.
Any kind of help is much appreciate. This is a real bugging situation. Thanks
I was doing a stupid mistake that was hard to identify bu #Matt's suggestion helped.
[self.fanOfViewController.containerView addSubview:self.fanOfViewController.userSimpleTableView];
[self.currentViewController.view removeFromSuperview];
[self.currentViewController removeFromParentViewController];
self.fanOfViewController.containerView = self.containerView;
[self addChildViewController:self.fanOfViewController];
[self.containerView addSubview:self.fanOfViewController.view];
//CLEAN UP THE CONTAINER VIEW BY REMOVING THE PREVIOUS ADDED TABLE VIEWS
[self.userWallViewController.activityFeedTableView removeFromSuperview];
[self.userFansViewController.userSimpleTableView removeFromSuperview];
Each time I was adding a new tableView from it's view controller by pressing the corresponding button I was stacking it in the current's view container. When I was trying to remove the corresponding viewController from the hierarchy and then add it again the viewDidLoad method was not called (it was only called the first time). The was where I had my logic of removing the tableView.
Now I'm also adding it when the button is pressed and remove the other tableViews from the "stack". It may not be the very best way but I do plan to optimize it. I hope this is clear enough and helps anybody that comes across this problem.