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

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];
}

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.

A view is presented on the click of a button. As soon as i click on the button, the view moves at the left

In my project, i have a button which presents a viewController (transitionStyle is coverVertical and modalPresentationStyle is FormSheet). I want the view should be presented at the centre but on the click of the button, the view opens at the left and then when the keyboard is put down it moves at the centre. Can anyone tell me why? I have used viewController.view.superview.center = self.view.center;
Check out my presentingViewController code which i have put in the click of the button.
Try this, see if it works
viewcontroller.view.superview.frame = CGRectMake((self.view.centre.x-540)/2, (self.view.centre.y-650)/2, 540, 650);
I got the answer to my question. Instead of using
[self presentViewController:vcRevaluateInventory animated:YES completion:nil];
for presenting the view, just use
[self presentViewController:vcRevaluateInventory animated:YES completion:^{
vcRevaluateInventory.view.superview.bounds = vcRevaluateInventory.view.frame;
}];

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

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

How can I make different buttons show different data on a single screen on iPad

I am making an app for iPad with different views. Till now I have added 2 views. First view is the home screen which has a single button and some images. Pressing button on first view navigates to the second view. Second view has 6 buttons. Now what I want to do is when I press any button on second view, it navigates to the third view. Each button on second view has to show different data. I don't want 6 different views, instead I want a single third view but it should show only that particular data respective to the button pressed on second view.
How can it be done?? Please help me with the code..
Any help will be highly appreciated..
You just need a variable in the third view that you set before showing it. I would set a different tag value for each of my buttons and have them all call a single method. In that method, check the tag value of the sender and setup the third view accordingly. Then show it.
In the third view's viewDidLoad method you can handle displaying or setting up the new data you assigned to it.
For example, if you were setting some custom text in the third view you would have this for your button method in the second view:
- (IBAction)buttonTap:(id)sender {
UIButton *tappedButton = (UIButton *)sender;
MyThirdViewController *thirdVC = [[MyThirdViewController alloc] initWithNib:#"MyThirdViewController" bundle:nil];
switch (tappedButton.tag) {
case 1:
thirdVC.customText = #"Something for button 1";
break;
case 2:
thirdVC.customText = #"Something for button 2";
break;
case 3:
thirdVC.customText = #"Something for button 3";
break;
}
[self.navigationController pushViewController: thirdVC];
[thirdVC release];
}
In the third ViewController:
- (void)viewDidLoad {
self.myTextView.text = self.customText;
}

Resources