How do I hide a button so that it turns see-through rather than white? - ios

I am trying to program a view which has a list of exercises in a table view. The user can either swipe them to delete or go into edit mode and click multiple rows to delete faster (much like in mail).
At the bottom of the screen there is a finish button where the user will click when s/he has finished choosing the exercises they want in their workout. Currently I am trying to bring up the toolbar when the user enters edit mode to allow them to delete their multiple choices. When this happens the view is compressed and so the finish button raises up above the toolbar. This isn't what I want as it looks stupid to be able to finish while editing something else.
I have tried hiding the button but this leaves a white square just above the toolbar
I am not sure if I need to make the button transparent or if I am hiding it incorrectly.
How can I have the bottom button disappear completely when edit mode is entered to the extent it doesn't affect my table view and then reappear and almost 'swap' with the tool bar when editing mode is exited?
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
// Activates multiple selection
exercisesSelectedTableView.allowsMultipleSelectionDuringEditing = editing;
// Lets us know we have clicked editing - changes it to done
[super setEditing:editing animated:animated];
if (editing) {
// This bit is done when someone clicks edit
// Sets the view into editing mode
[exercisesSelectedTableView setEditing:editing animated:YES];
// Unhides the tool bar
[self.navigationController setToolbarHidden:NO animated:YES];
// Hides the finish button
[finishedButton setHidden:YES];
}
else {
// This bit is called once someone clicks done
[self.navigationController setToolbarHidden:YES animated:YES];
// Reveals finish button
[finishedButton setHidden:NO];
[super setEditing:NO animated:YES];
[exercisesSelectedTableView setEditing:NO animated:YES];
}
}

Found the answer to this out eventually.
Using the setToolBarHidden works fine but in the XIB file I needed to check that the table view went all the way down to the bottom of the view. As it was the table view only went to the top of the finished button. Therefore when it was hidden it left the white gap I assumed was the shadow of the button.
Morale of the story: Check the XIB files carefully

Related

UINavigation PushViewController Doesn't Display Next View, But Runs The Code

The problem, My home screen is wrapped in a UINavigationController, when I push to the next controller it's fine, but then when I use the left swipe to go back to the home screen then click on the button to take me to the next controller sometimes it works fine about 60% other times it just hangs there. I can see the code executing in my logs as if the view controller has been presented but it's not on screen...
So at this point the whole UI is unresponsive, the only thing I can do is swipe from Left to Right like I want to go back to another page, but this is where it gets funky, the screen that I was trying to display then slides in view from the right side of the screen.
When I let go it reloads the home view, then the app works as designed.
I have no idea whats going on with this thing... Below is my code for presenting the next view:
NextViewController *nextViewController = (NextViewController*)[self.storyboard instantiateViewControllerWithIdentifier:#"NextViewController"];
nextViewController.nameString = [[self.topArray objectAtIndex:[indexPath row]] objectForKey:#"Name"];
nextViewController.championMCID = [[self.topArray objectAtIndex:[indexPath row]] objectForKey:#"UserId"];
[self.navigationController pushViewController:nextViewController animated:YES];
When I get to the next screen because i'm hiding the navigationbar, I am setting the following:
[[self navigationController]setNavigationBarHidden:YES animated:NO];
self.navigationController.interactivePopGestureRecognizer.delegate = self;
And that's it, not quite sure what's going on but any help would be great help thanks.
I integrated a left side menu, that operates as a settings screen, and I believe that the:
self.navigationController.interactivePopGestureRecognizer.delegate = self;
And that left side menu were clashing, when I say clashing I mean, when I pop the next view controller, I believe somewhere in the stack that the views got tangled up. So when I push to another view, the app doesn't know rather to use the left side menu or to use the navigation controller without the left side menu...
So instead of allowing the:
self.navigationController.interactivePopGestureRecognizer.delegate = self;
I decide to place this code in my viewwillappear method:
self.navigationController.interactivePopGestureRecognizer.delegate = self;
NSUInteger viewControllerCount = self.navigationController.viewControllers.count;
NSLog(#"viewControllerCount %ld", viewControllerCount);
if (viewControllerCount == 1)
{
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
else
{
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
I placed this code in the initial navigation controller so whenever I push, the left side menu will be on every screen within the app, and then I implemented a back button on each screen so that I can pop the views instead of sliding left, I didn't want to implement the UINAVIGATIONBAR at the top because I need that small piece of screen as well to display everything haha...
I hope this helps anyone in the future that may have the same issues, good luck, happy coding.
I had this issue too and what I noticed was that my current view controller was not embedded in a UINavigation controller so on using navigationController?.pushViewController(viewController, animated: true) my current navigationController was null

How can I assign a pointer to the keyboard before I have assigned first responder

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.

UISearchBar Cancel button is visible but doesn't work

I have the same problem as Using becomeFirstResponder causes cancel button to not work, except that the solution doesn't work in my case.
I created a storyboard project with a Navigation controller and a Table view controller in it. I added a UISearchDisplayController to the table view and all works well until I try to access the searchDisplayController as seen below in the code snippet. I am using a section index and added UITableViewIndexSearch (or #"{search}") to the top of the section titles so that the magnifying glass shows at the beginning of the A - Z index. When I click on the section index the following function is called:
- (NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
if ([title isEqualToString:UITableViewIndexSearch])
{
[self.searchDisplayController setActive:TRUE animated:TRUE]; // Either of these two lines
[self.searchDisplayController.searchBar becomeFirstResponder]; // will cause the search bar cancel button to not work
return 0;
}
return index - 1;
}
If I comment out both of the lines that access searchDisplayController then the search bar cancel button works as expected. If either of the two lines is not commented out in the code then the cancel button on the search bar acts as if it were not even there. Removing the becomeFirstResponder line means that I must click/touch in the search bar field to transfer focus to it, so in this case when I click on the cancel button the search bar gets focus. It's as if the cancel button is seen transparently through the search bar but can't be clicked/touched. Take those two lines of code out and the cancel button works again.
What the heck is going on?

Previous view cutting off at top after view on top is closed

I have a main view and two sub views that load whenever the corresponding "Read More" button is pressed.
Both these buttons are programmed the same except that they load different views and pass different data (although the layout and functionality of both are the same).
When the first button is pressed everything remains normal by having the new view appear on top and I can click close to get rid of it.
When the second button is pressed the top view appears and can be closed but the original view somehow moves up and gets cut off.
It's a little hard to explain so I created a quick video to show you what is happening:
http://screencast.com/t/Yyy8J1BSnj
As you can see I can click the first button, launch the new view, close it and everything remains the same. When I click the second button the new view launches and I can close it but then the original view moves.
Any idea what is causing this?
This is the code that launches the two views:
- (IBAction)readMoreBackground:(id)sender {
NRMReadMoreBackgroundViewController *readMoreBackgroundController = [self.storyboard instantiateViewControllerWithIdentifier:#"readMoreBackgroundID"];
// Passing background text to the backgroundFullText variable for use on next view
readMoreBackgroundController.backgroundFullText = self.backgroundText.text;
[self presentViewController:readMoreBackgroundController animated:YES completion:nil];
}
- (IBAction)readMoreInscription:(id)sender {
NRMReadMoreInscriptionViewController *readMoreInscriptionController = [self.storyboard instantiateViewControllerWithIdentifier:#"readMoreInscriptionID"];
// Passing inscription text to the inscriptionTextFull variable for use on next view
readMoreInscriptionController.inscriptionTextFull = self.inscription.text;
[self presentViewController:readMoreInscriptionController animated:YES completion:nil];
}
and this is the code that closes the views when the close button is pressed:
- (IBAction)closereadMoreBackgroundView:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)closeReadMoreInscriptionView:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}

UINavigationBar : repaint?

I'm facing a problem I don't understand.
In my main view, I have a button heading to another view. Everything is embedded in a NavigationController.
I successfully changed the background image of my NavigationBar in my main view. But when I click on the button to display my other view, my NavigationBar's isn't repainted although I'm using this code :
- (IBAction) toOtherView : (id) sender
{
if(!otherView) otherView = [[OtherViewController alloc] initWithNibName:#"OtherViewController" bundle:nil];
[self.navigationController pushViewController:otherView animated:NO];
}
However, I also have a Dark Info button on my main view (I choosed the default Utility Application at first). It flips to another view and when I come back to my main view, the NavigationBar image has been changed. So I guess it's a problem of repaint. But what can I do here ?
Thanks a lot for your advices.

Resources