I have a popover that contains a UITableView. This UITableView has a cell with a text field in it:
alt text http://cl.ly/1b50a21ca8202d22db1b/content
When the popover opens near the bottom of the screen, and I tap the text field to edit it, the keyboard comes up, and the popover moves up to avoid being covered by the keyboard. But as it moves up, the table view in the popover scrolls up out of bounds:
alt text http://cl.ly/4fe64fbfe9518f20560d/content
I can scroll it back down, but how do I prevent this from happening.
I've come to the conclusion that this is a bug. I have filed a bug report with Apple (rdar://8156616) as well as a report on OpenRadar.
For anyone interested, here is a sample project that demonstrates the issue.
Try disabling scrolling on the table view.
[self.tableView scrollingEnabled:NO];
How are you setting the content view of your pop over controller. Please try editing the auto-resizing mask of the content view and set it from top-left.
Hope this helps.
Thanks,
Madhup
Perhaps you can set the UITableView's contentSize manually? So that there is no excess for it to scroll up.
I had the same problem but when hiding the keyboard and reloading the table view!
There is one solution for this problem! What you have to do is first hide the keyboard and reload the table view or change the table view in method recieving keyboard did hide notification!
At first I called
[textView resignFirstResponder]; or [textField resignFirstResponder];
and then
-(void)keyboardDidHide:(NSNotification *)notif {
//Check some conditions if you want
[tableView reloadData];
}
You need to listen to the keyboard will show notification:
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardStatusForPopover(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
Then you have to see if the keyboard frame intersects with the popover and subtract the values added from the keyboard to the popover container frame:
#objc func handleKeyboardStatusForPopover(_ notification: Notification) {
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
if keyboardSize.intersects((self.resultPopOverTableViewController!.view.superview!.superview!.frame).insetBy(dx: 0, dy: 60)) {
let popOverContainer = viewControllerDisplayedbyPopover?.view.superview!.superview!
// cellDisplayingDetailInfo = sourceview of popover
popOverContainer!.frame.origin.y = popOverContainer!.frame.minY - keyboardSize.height + cellDisplayingDetailInfo.frame.maxY
}
}
}
Related
I have a popover with TabBarController in it. In one tab there is a TableViewController with a list of names. And there is a plus button, that has a modal segue to AddCharacterVC for adding new names.
In iOS 7 I do it like this:
AddCharacterViewController *acvc = (AddCharacterViewController *)segue.destinationViewController;
acvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
acvc.modalPresentationStyle = UIModalPresentationCurrentContext;// so it does not take full screen in popover
And in AddCharacterVC I set content size like this:
- (void)viewWillAppear:(BOOL)animated {
CGSize size = CGSizeMake(320, 480); // size of view in popover
if (IDIOM == IPAD && [self respondsToSelector:#selector(preferredContentSize)]){
self.preferredContentSize = size;
}
And it works perfectly.
However, in iOS 8 modal view does not cover the whole popover, leaving TabBar visible. The user can tap on it or not, anyway modal view won't unwind properly.
I've tried:
setting acvc.modalPresentationStyle to UIModalPresentationOverCurrentContext
tried to set TabBar hidden
checked in storyboard that edges of TableVC extend under Bottom Bar and Bottom Bar in Modal View (AddCharacterVC) is set to none
All with no results.
Now the only thing I can think of is to try making modalPresentationStyleCustom and use UIPresentationController (I'm trying to do it now, but I haven't done it before). Am I missing something? Could there be other way to do it? Sorry, I cannot post images here yet. Many thanks in advance!
Ok, so I've set the modalPresentationStile to UIModalPresentationCustom, and used UIPresentationController - I've just copied code from WWDC-14's LookInside project and modified it a bit.
I'm not sure if it was the best solution, but it worked in my case.
I'm trying to have some text in a UITextView change color (and sometimes change text) after a button press:
I have loaded a text view in ViewController with a simple string in viewDidLoad
self.answer1TextView.text = questions[1];
The above displays just fine.
There is button next to it, which triggers the following method (also in ViewController):
- (IBAction)select1ButtonTapped:(id)sender {
self.answer1TextView.textColor = [UIColor redColor];
}
The problem is this: when the button is tapped, the text in the UITextView doesn't change color, and the right half of the view disappears.
I'd greatly appreciate some advice on this. Thank you.
I am using UIPopover to display videos using UIImagePickerController.In this I have to dismiss my popover when use is clicked.Can anyone please help me to do this?
Also I want to change the size of the popover.Now I am using the below code to chane the size.But it is not working.Width is not getting changed.
[popOver1 setPopoverContentSize:CGSizeMake(1000.0 , 500.0) animated:YES];
Please give me a solution for these two problems..
For dismissing popover controller you can use below code in button action method.
[popoverController dismissPopoverAnimated:YES];
For changing the width you can change the frame of the popover controller not contentSize.
popoverRect = CGRectMake(x, y, width,height);
i found you are trying like this
[popOver1 setPopoverContentSize:CGSizeMake(1000.0 , 500.0) animated:YES];
//it means in increases the contentSize not the width
I've got a UITableView with the ability to delete the rows using edit mode etc. As standard, when you tap the 'edit' button, you go into edit mode and the content of the cells gets moved to the right. If you do a 'swipe to delete', the cell content stays where it is.
What I want to do is increase the indentation when you enter edit mode. I've tried the UITableView delegate method indentationLevelForRowAtIndexPath but that doesn't seem to work when I'm using a UITableViewCell subclass.
In the end I used the layoutSubviews method in my UITableViewCell subclass. Below is my code:
- (void)layoutSubviews
{
[super layoutSubviews];
CGRect b = [self bounds];
if(self.editing && !self.showingDeleteConfirmation){
b.origin.x = 42;
}
[self.contentView setFrame:b];
}
This indents the cell content further when you enter edit mode and thanks to the "!self.showingDeleteConfirmation", when you do a 'swipe to delete', it doesn't indent it.
However, when you tap the 'edit' button, then tap one of the circle delete buttons, the cell content slides back to the original 0 x axis position. This is because the showingDeleteConfirmation is now set to true.
I've tried to fix this by checking what the current origin.x value is, but every time I check, it's set to 0.
Is there a way I can achieve what I want?
I am using uiwebview in my code and implemented swipe function on uiwebview. For swipe function i have set YES for scaleToFir property for webview, when we give, scaleToFit=YES, content get shrinked. But for my case both needed. swipe aswell as content should not shrink. But disable horizontal bar is fine. can you please help me out?
Srini
for (UIScrollView *scroll in [webview subviews]) {
// Make sure it really is a scroll view and reset the zoom scale.
if ([scroll respondsToSelector:#selector(setZoomScale:)]){
scroll.bounces=FALSE;
}
}
Try This:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(#"loaded");
[webView.scrollView setContentSize: CGSizeMake(webView.frame.size.width, webView.scrollView.contentSize.height)];
}