I have a UItextView inside a UITableViewCell. When I select some text inside the textview, I have a strange animation: the cell or the textview (I don't know wich scrollview is really moving, may be both) start scrolling up and down maybe because both scrollviews (Tableviewcontroller's scrollview or UItextView's scroll view ) want to focus the selected text for their own in different ways. I've tried anything but this bad animation is still here.
The Tableviewcontroller and the textfield was made with storyboard.
ps: sorry for bad english
Use
[tableView setScrollEnabled:NO];
when the textView is focused.
if you want to show a static text just use the uilabel, which is enough.
but if you want to show and let the user edit the textview, you may allow to edit it while the tableview is in edit mode.
Related
My situation is that I have a collectionView which has two types of cells. The first cell type is a simple editable UITextField, then second contains a UITableView with editable UITextFields inside its cells.
My problem is that when the keyboard shows up due to the text fields inside the a table view cell and I change contentInset the change does not take place.
This is the code I am using to change the insets when the keyboard appears and its the same code for when the textfield in the collection view cell is selected, which works.
self.view.setNeedsLayout()
self.collectionView.contentInset.bottom = inset
self.view.layoutIfNeeded()
There must be something that I can't think of that is preventing contentInsets to change.
I also have a custom UICollectionViewLayout although I don't think this matters as that is only concerned with the contents of the collectionView, not the insets.
Any help would be much appreciated.
Turns out the reason it was working was because the cell with the textview in it was doing some magic autoscroll, while the cell with the table view textview was not, I'm guessing as it was to far nested in the view stack to handle this.
My fix was to adjust the contentOffset so as to force a scroll.
I use custom cells of subclassing UITableViewCell in a table view. And There must be space between cells. I succesfully add the space with adding a subview that I called SpaceView into the content view. But When I touched the spaceView, it is perceived as I touched the cell. And didSelectRow method called. I tried to set spaceView's UserInteractionEnabled==NO. But It doesn't work.
So my question is; Is this the right way I used to add space between cells ? Should I try to add cells for making the space ? or If its the right way, How can I prevent calling "didSelectRowAtIndexPath" method when I touched spaceView ?
like Inder said below, u can use an UIButton to solve the issue.
1) in your custom cell: at the bottom of your custom cell add a blank UIButton with the height u actually need between cells, and customize its background color according to your needs.
2) in cellforrowatindexpath: disable button of each cell. (or you can also do that in Interface Builder of previous step)
result: u have a clear disabled button that will appear as required space between cells.
Make your spaceView as UIButton (I guess it's UIView right now)
When you add UIButton that touch will be consumed by the button thus touch won't be passed to it's parent.
OR
I'm not sure if it will work or not, you can add tap gesture to your spaceView
I have a UITableView in which I have several custom cells and my last cell contains a UISearchbar in it. I have wired up the appropriate delegates and referencing outlets and can get the keyboard to show up.
The problem I am facing is that the searchbar is at the very bottom of my tableview i.e. it is part of the very last cell. So even though the keyboard gets shown, the searchbar is hidden below it as I suspect it is unable to scroll to that location since its the last cell in the view.
Does anyone have any thoughts on this and how to overcome this situation.
The easiest solution is to have your view controller be a subclass of UITableViewController. This type of view controller will handle issues exactly like these.
If you cannot, you should listen to keyboard will show/hide notifications and set contentInset and scrollviewIndicatorInsets bottom of the table view to the keyboard height. Then you can scroll the specific cell into visible. When the keyboard hides, set the bottom to the previous value.
Yes....Two ways
1) either you can change the frame of whole tableView and pull the whole table up by decreasing the y position of tableView
[tableView setFrame:CGRectMake(100,100,100,100)];
or
2) You can change the contentOffset of the table to programatically scroll the tableView's last cell so that it is visible to the user.
[tableView setContentOffset:CGPointMake(0,400) animated:YES]
Hope this will help you.
I have a custom table with just three cells. In third cell I have a textView. The three cells cover up enough space on the screen so that just the keyboard space is left. I don't want anything to be movable or scrollable, so I used self.tableView.scrollEnabled = NO;.
This is working fine with earlier version of iOS. However with iOS 5, it shows some weird behavior. When I enter multiple lines of text in textView the whole table scrolls up. Ideally the table should stick there and only textView should scroll.
After trying lots of things I found that the textView is placed so near to the keyboard (as the textView is placed in last cell and just below it is the keyboard) that the iOS tries to move the textView up, for which it scrolls the complete table up. Is there any way to stop this auto scroll of tableView.
I found the same problem mentioned here
Disable UITextView scrolling the containing view?
however it is also not answered yet. And the workaround mentioned over there won't work for me as my containing view itself is scrollable (UITableView)
for me, i work around with scroll in table view like this
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if(self.tableView.contentOffset.y != 0)
{
self.tableView.contentOffset = CGPointMake(0, 0);
}
}
One solution is to add a completely new subview on the fly. Add a UITextView to self.view and give it a frame that corresponds to the same position on the screen. The table view should not scroll now.
In case this does not work because self.view is the table view, change your controller into a class UIViewController and implement the delegate and datasource methods yourself (i.e. you have to mention them in the #interface declaration). The table view should then be a subview of self.view and you have to hook it up via IB.
Before you dismiss the keyboard, copy the content to your original text view.
I have a UITableView with a few UITableViewCells. Each cell contains a UITextfield. Tapping the textFields causes the keyboard to display. Unfortunately the keyboard covers some of the cells that are lower on the iPhone's screen.
What's the easiest way to scroll the tableView up when the keyboard is displayed?
I've experimented with the contentOffset. This works for actually scrolling the tableView. However I'm having trouble determining which cell is "active" (has a textField that's currently the firstResponder). My app supports both portrait and landscape orientation so the tableView sometimes needs to be scrolled when the device rotates.
A simple way to keep track of which textField is currently active is to set its tag property to the indexPath's row on cellForRowAtIndexPath:
Another way is to use this line:
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:[textField convertPoint:textField.frame.origin toView:self.tableView]];
on textFieldShouldBeginEditing: for when the textField becomes active, or on your rotation callbacks for when the device rotates, and then scroll the tableView using scrollToRowAtIndexPath:atScrollPosition:animated:
I am writing an app that has a similar issue. The way that I am handling keeping track of the first responder, or active UITextField, is by using a callback. I call a method using the UIControlEvent UIControlEventEditingDidBegin.
Where I setup the UITextField:
[self.nameUnitNumberField addTarget:self.textFieldDelegate action:#selector(handleEditingDidBegin:) forControlEvents:UIControlEventEditingDidBegin];
Then in the delegate class, I set the current text field:
- (void)handleEditingDidBegin:(id)sender
{
self.currentNameField = (UITextField *)sender;
}
This seems to be working well. It also avoids the use of tags. I've heard that there are potential problems with it and it's best to avoid it when not needed.
Once you have the active UITextField, you can use either the contentInset and scrollToRowAtIndex: as described here: Get UITableView to scroll to the selected UITextField and Avoid Being Hidden by Keyboard
or just resize the table view while the keyboard is on screen. That would be simplest way to do it.