how to stop UITextView to scroll UITableView - ios

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.

Related

UITableView didSelect delegate doesnt gets called?

In my app, I have added an UITableView over a ScrollView. I have disabled scrolling in table view.
So, only the scrollView Scrolls, I have adjusted the scroll view content Size with the tableView Frame. So, I can access all the cells.
Consider, there are 5 rows visible in the screen, if I tap any of the row, the didSelectRowAtIndexPath method gets called. If I scroll down, say to 6th cell and tap on it. The method doesnt gets called.
Same issues happens with UIcollectionView.
The reason why I have added so is. When I scroll the Scroll View, a view in that should get fixed in the top and the tableView behind it should go on scrolling. You might have seen in many of the apps in Android. So, I have used the ScrollView didScroll delegate to get the offset position. As per it, I will make the view to be fixed and vice versa.
Make the height of UITableView same as the content height of table.
Then set the content size of UIScrollView as the height of UITableView
Here is a brief example to demonstrate
CGRect rect = tblTopics.frame;
rect.size.height = tblTopics.contentSize.height;
tblTopics.frame = rect;
self.scrlVwFacultyDtl.contentSize = CGSizeMake(self.scrlVwFacultyDtl.frame.size.width, tblTopics.frame.size.height);
In the above example the tblTopics is the instance of UITableView and scrlVwFacultyDtl is the instance of UIScrollView
hope it will help you..

Swift; is scrollView with tableView feasible?

I've have been trying for a while now, to implement a specific behavior in my app. On the initial view of my app, there must be a logo(imageView), a label and a textField. It should be possible to scroll down from the initial view, to a tableView. while the user scrolls down, the label in moved up in the window, to form a search field for the tableView. Then the scrollView should lock to the part with the tableView, and it should only be possible to scroll back up, if dragging elsewhere than the tableView.
What is best practice for doing as described?
The image show (only for illustration, i havn't been using story board when trying to implement it) an overview of the problem:
The way I've tried to do this so far, is by embedding the tableView in a scrollView (as seen on image), enabling paging on the scrollView, and than disabling scrolling on the scrollView, when the buttom part has been reached. I've added a gesture reconizer on the part with of the screen with the textField.
These two posts (Scrollview with embedded tableview and Use Pan Recognizer to Control ScrollView) descripe i further detail what i've tried so far.
But the question is more to, is there an alternate solution for making behaviour descriped above?
Maybe interactive animated transitioning between view controllers somehow?
YES there are! Implement a table view with a header view. And remove the scroll view.
self.tableView.tableHeaderView = topView
where topView will be the view wish as the UIImage, the label and textField

UITableView stops scrolling enough after I add/remove a view to the superview of table view

Here is the problem that I'm facing. I have UITableView inside main view. When user taps menu button, view is added to the view hierarchy of superview, and this view covers all screen, except the menu button. That is I call
[self.view insertSubview:self._menuView belowSubview:self._menuButton]
After user clicks the menu button again I call
[self._menuView removeFromSuperview]
However, after this, the UITableView stops scrolling, actually it scrolls, but just a little, couple of pixels, and then bounces back to the location on which it was before I inserted _menuView. I've monitored the menu hierarchy after inserting and removing the _menuView, it is actually removed, and also there is no view which covers the UITableVIew, so there is no chance that some other view steals touches from UITableView. What can be the problem? Any ideas?
EDIT 1: I've noticed besides not being able to scroll, another strange thing happens. When I show menuView, the tableView is scrolled to top, without animation. (the menuView is half opaque only, so I can see the tableView underneath it)
EDIT 2: I've monitored contentSize and contentOffset of tableView before and after inserting _menuView, the reason for not being able to scroll is that somehow contentSize is being changed.
TABLE VIEW BEFORE INSERTING MENU - contentSize:{Width=320, Height=10519} contentOffset:{X=0, Y=3980}
TABLE VIEW AFTER INSERTING MENU - contentSize:{Width=320, Height=44} contentOffset:{X=0, Y=0}
As You can see, the height is changed to 44 that's why I'm not able to scroll. And Also, as I've said in EDIT 1: tableView is scrolled to top - so as you can see contentOffset is also zeroed. Any ideas why content size changes automatically?
Thanks in advance.
i think there is problem with your tableview frame. right after removing subview, try to set frame of your tableview at its original frame.may this will solve your problem
Content in the UITableView organized automaically and designed only to show cells & header/footer elements. To proper working you should wrap your table into parentView and add your menu to that parentView rather than to the UITableView. You can also try to call reloadData method on table since it can restore the content size of the view.

UISearchbar inside UITableView as the last cell hiding the keyboard

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.

Anchor a UIButton to the bottom of a UITableViewController's view

I have the following requirement. When a UITableViewController's view is displayed, there are a variable number of rows. Underneath the rows, a button should be displayed.
When the number of rows is small, the button should be anchored to the bottom of the view.
When the number of rows is larger, the delete button should be placed immediately after the last row.
In other words:
And not:
My best attempt at this so far has involved setting a tableFooterView and trying to update its height using the contentSize of the UITableView, but I am running into all sorts of problems. I might continue down this path and ask for some help, but first I want to know if anyone has alternative (better) solutions.
The result must play nicely with a double-sized status bar (during a call for example) and I am targeting iOS 6.0. I am not using interface builder.
One possible solution to achieve this effect might have to use two different solutions.
If the amount of rows means that the button will be off the screen then use the footerView like you have been doing.
If the amount of rows means that the button will not be off screen then
Add the button to the tableView
Implement - (void)scrollViewDidScroll:(UIScrollView *)scrollView and update the frame of the button to be offset from the bottom.
The offset from the bottom might follow some logic like this
yOffset = CGRectGetHeight(tableView.frame) - (CGRectGetHeight(button.frame) + somePadding)
yOffset += tableView.contentOffset.y
This would mean that the button still moves up and down with the scrolling but you don't have to mess with the footerView height
Keep both the table view and a button inside scroll view. Keep the button at the bottom of the scrollview. For proper scrolling to work you might want to set the scrollEnabled property of the scroll views. For more details on that check this up
Scrolling a UITableView inside a UIScrollView
EDIT:
yourView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin ;
Check the accepted answer for this question for more details on implimenting struts and springs using code:
UIView autoresizingMask - Interface Builder to Code - Programmatically create struts and springs - Swift or Objective-C

Resources