Stop cell from being dragged out of UITableView bounds - iphone

I have a UIVIew on which I loaded a UITableView as subview. The tableView is exactly the height of all it's rows(4 of them) heights sumised, about half the height of the main view.
The problem is that when I drag a row to move it I am able to drag beyond the bounds of the table and this cuts my cell's view (I am only able to see the part that is still in the table's bounds).
Is there a property I can change to stop the cell from being dragable out of the table's bounds?

you can do this like below..
[yourtableview setBounces:NO];
let me know it is working or not!!!!
Happy Coding!!!

If the UITableView is exactly the height of the 4 rows . Then you Do Not Need the Scrolling functionality of the UITableView and you can simply stop the scrolling by :-
TableView.scrollEnabled = NO;
Hope this is what you wanted . Please tell otherwise.

Related

How to make a scrollable view in iOS?

i am looking to create an "options" page for my application and because they are many , the screen of the phone is not enough to show.
So i need the user to be able to scroll down the view to see more options till the last. I know i should use the scrollview , but i dont know how.
All the tutorials i ve found are about scrolling all over the screen , zooming , scrolling from left to right , but nothing on how u can create a simple page scrolling up and down.
How exactly do i do that? Do i make many .nib files and somehow i connect them? Do i make a big .nib file?
Can someone guide me to a tutorial on that?
Use ContentSize property of UIScrollView to scroll what ever area you want. i.e.
take UIScrollView add it on UIView with exist height of iPhone. i.e. max 460.0
So ScrollView frame will be max (0,0,320.0,460.0).
Now after adidng ScrollView to View set ContentSize property to upto scrollable area.
[self.mainScrollView setContentSize:CGSizeMake(self.mainScrollView.frame.size.width, 1000.0)];
UIScrollView *mainScroll = [[[UIScrollView alloc]initWithFrame:CGRectMake(x,y,w,h)]autorelease];//scrollview width and height
mainScroll.scrollEnabled = YES;
mainScroll.userInteractionEnabled = YES;
mainScroll.showsVerticalScrollIndicator = YES;
mainScroll.contentSize = CGSizeMake(width,height);//width and height depends your scroll area
..........
//add subviews to your scrollview.....
[mainScroll addSubview:view1]
............
[mainScroll addSubview:view2]
..............
[mainScroll addSubview:view3]
[self.view addSubview:mainScroll];
Note :: contentSize property determines your scroll
area.Scrolling
enabled only if your scrollview content larger than scrollview height..
You could use a Table View with static Cells, that will scroll automatically if it needs to, much easier. Also with a Table View you can choose to scroll up, down, left, right, set bouncing etc from the Attributes Inspector.
Make only 1 nib file.
give height of scroll view large as you want.
then place your buttons , textfeild on scroll view
There are two ways :
make settings bundel for your app check this Press Me
to make UITableView with custom cells >> it is easy if you use
Interface Builder Press Me

TableViewController for scrolling horizontally

I need a tableviewcontroller that scrolls horizontally instead of vertically.
Is there one available? Because I have to use a scrollview now which might get memory hungry after a while!
Try implementing this in a UIScrollView, and reuse your cells.
We have used UIScrollView for each cell and we scroll them together when either of them is scrolled. Our app has loads of data in the tableview and we are doing fine. You can try this approach.
I would make my own horizontal table view that inherits from UIScrollView. Implementing your own dequeueReusableCellWithIdentifier: isn't very hard.
What about using the standard one, then rotating the contents of each of the cells by 90 degrees?
It would have the same effect for the end user.
You could rotate your UITableView 90 degrees.
Yes most definitely this is possible. It is possible to do so.
STEP-1:
You just have to put your tableView under a UIScrollView in your Interface Builder or by coding as per your liking (i.e. as a subview of UIScrollView)
Using coding you can do that as
[scroll addSubView:tableView];
STEP-2:
Then you need to make the width of tableView more than size of the View. So tableView Width is more than 320 (say it is 600)
[tableView setFrame:CGRectMake(0,0,600,460)];
STEP-3:
Then you just have to set the UIScrollView's ContentSize as CGSize(600,460)
like
scroll.ContentSize = CGSize(600,420);
Now just build and run and You are done.
Hope this helps you. :)
If you have any doubts then please leave a comment here.
Remember: In any case you need to re-use your tableViewCells as otherwise it would leak memory.
EDIT:
You can refer the basic logic here for rotating your tableView by 90 degrees, though it is about UIImageView rotation by 90 degrees but I think this will help you.
How to programmatically rotate image by 90 Degrees in iPhone?

Accessing grouped UITableView section view?

Basically I want to "cut the corners" of the first cell imageview and the last cell imageview to match the curved corners on the grouped tableview section.
I was given the advice to do this by setting the view's masksToBounds property to true?
Anyone know how to access this view? Doing cell.superview doesn't work. cell.contentView.superview doesn't work and cell.backgroundView.superview doesn't work.
Anyone have any ideas?
There is no section view. A cell's superview is the UITableView itself.
The rounded corner drawing is done by UITableViewCell's backgroundView, and backgroundView isn't in imageView's view hierarchy (contentView and backgroundView are siblings—their superview is the Cell itself), so unfortunately masksToBounds won't work.

UITableView details as a subview

I have a UITableView in iPhone with enough cell to make it scrollable.
I would like to have a subview display whenever I click on a cell, rather than using the navigation controller behaviour.
The problem is that I cannot calculate the CGRect exactly to have the subview always centered in page, because the CGRect is calculated from top of table, and if I scroll table and click cell, the subview will be added out of screen.
The solution could be easy, but I don't know if it's possible: identify the portion of the current viewable area of the UITableView and obtain in some way the frame and therefore origin and size, then build a subview based on such coordinates.
Do you think it's possible without writing not too much code ?
thanks
Leonardo
A simple solution is to not add your sub view as a subview of the UITableView but of its parent (or the main application window). So instead of doing something like:
[myTableView addSubview:mySubView];
do:
[[myTableView superview] addSubview:mySubView];

UIScrollView not showing scroll indicator

I have a UIScrollView which I create and size dynamically using...
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width , length);
I then add subviews to the UIScrollView.
I do have scrollView.showsVerticalScrollIndicator = YES;
When scrolling the scroll indicator never appears.
Even if I call [scrollView flashScrollIndicators] nothing happens.
Ideas?
Had the same problem and couldn't find the cause. The last answer gave the final hint: whenever I added new subviews I first removed all existing subviews from the scrollview (and apparently also the scroll indicators).
After checking in my loop, if the subview really was of the kind I wanted to be removed the scroll indicators showed up:
for (NSObject * subview in [[[scrollView subviews] copy] autorelease]) {
if ([subview isKindOfClass:[MySubView class]]) {
[(MySubView*)subview removeFromSuperview];
}
}
Update: changed code to Nikolai's suggestion
When I've dealt with this before, in my implementation of a grid, I would occasionally get some cells over the top of the scroll indicator. To fix this I am now inserting subviews at index 0 rather than adding them, which adds them to the top. So try something like this:
[scrollview insertSubview:subview atIndex:0];
For me, the horizontal indicator had mysteriously disappeared in my app on iOS 7. Later found out that for some strange reason, I had to enable both Shows Horizontal Indicator and Shows Vertical Indicator to make the horizontal one show up. If I set it to not show the vertical indicator, it would also not show horizontal indicator.
I fix this by adding this code after add new subview:
self.showsVerticalScrollIndicator = NO;
self.showsVerticalScrollIndicator = YES;
It will also happen (at least in the case of a UITableView) if the contentSize is too small for the table view to scroll. If you have enabled bouncing, then the tableview does not actually scroll and does not display the indicators therefore. Try fitting more content inside.
It can happen also if the parent of the scrollview is smaller horizontally than the scroll view itself :
The scroll bar is stuck to the right side of the ScrollView / TableView and this right side is not visible due to the parent bounds ( with a clipToBounds hidding it for instance).
I've seen this issue so I share it in case it can help.
Just check the width of your ScrollView's frame not to be bigger than the width of its parent view frame.
Two conditions,
If you are using a storyboard
If you are using a UITableView inside a UIViewController
Then, you should check your indicator insets are set to 0 (or any other number that is relevant to your autolayout):
Noticed this when the UIScrollView was a 48 px tall horizontal band, scrollable horizontally. Maybe Cocoa decides the area is too small for a scroll indicator...