configure UItableView not to scroll on iPhone - iphone

How do I set uitableView not to scroll So that it is fixed with two rows

Use:
tableView.scrollEnabled = NO;
if you wish to fix the size you sould set the frame to be for 2 row's size:
tableView.frame = CGRectMake(x_position,y_position,width,height);
good luck

use this code:
tableView.scrollEnabled = NO;

Related

How to disable scrolling in UITableView when the content fits the screen?

How to disable scrolling behaviour in UITableView, when the content fits the screen.
self.tableView.scrollEnabled = NO;
or this: if you don't want it to bounce:
tableView.alwaysBounceVertical = NO.
try this:
tableView.bounces = NO;

how to scroll the scrollview after inserting textview?

I've a problem that I want to insert many lines in my scrollview from a textview but I want that after inserting 6 lines the scroll will be enabled not before it. please some one help me..
Initially set the scrollEnabled property of the scrollView to NO, and set it to YES after inserting those six lines.
You will have to put a condition according to the number of characters. Roughly determine the number of characters in six lines. Store the textView text in a string and use the following condition:
NSString *textString = myTextField.text;
if ( [textString length] < NUMBER_OF_CHARACTERS_IN_SIX_LINES )
{
[myScrollView setScrollEnabled:NO];
}
else
[myScrollView setScrollEnabled:YES];
You shoud set the scrollView's contentSize accordingly.
Assuming it's a vertical scroll, find the height of text/ scrollView and set it like this:
scrollView.contentSize = CGSizeMake(newHeight,width);

Display a tableView over another view

I would like to achieve a similar effect:
http://imageshack.us/m/695/3715/img0419s.png
My initial idea was to create something like presentend in this schema http://imageshack.us/m/9/9227/img0413.png. Ie a ViewController with 2 subviews: a classical one with some information, and a tableView below which should scroll over the previous view.
But I realized that dividing the main view this way couldn't allow my tableview to scroll over the first view.
So I'm asking how this effect is possible. Maybe by setting a transparent header ?
Thanks for your help
Following the teriiehina's advise, here is how I dit it :
In my UITableViewController, I set a 50px contentInset and a transparent color to my tableView.
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.contentInset = UIEdgeInsetsMake(50,0,0,0);
I added an additional view on the top of the view (same size than the contentInset)
TTView *test = [[TTView alloc] init];
test.frame = CGRectMake(0, 0, 320, 50);
test.backgroundColor = [UIColor grayColor];
[self.view addSubview:test];
Finally, in order to let my tableview scroll over the additional view, I brought it in the front
[self.view bringSubviewToFront:self.tableView];
Now I just have to set a custom color for my cells.
A dirty trick here:
Add the UIView that contains the name first
Add a UIScrollView with clipBounds = NO. That view will contain the message.
That should work for you
I think you can achieve this effect using the contentInset property of the UITableView (which is a UIScrollView subclass) and presenting the tableView at first with a programmatic scroll.

[iPhone]How to set padding of grouped tableview section?

Hi I have a grouped tableview and i need to change the padding of sections.I need to have between 2 sections 10px.
I have tried to dissmiss header like that:
CGRect frame = [myTableView rectForFooterInSection:indexPath.section];
frame.size.height = 0;
CGRect frame1 = [myTableView rectForHeaderInSection:indexPath.section];
frame1.size.height = 0;
But it does not work.
Can i change the padding.If you want some example i find:Add event in calendar on iPhone
thanks
Those frames are not pointers, when you change them the original rect isn't affected. They are stored separately in memory.
It seems like the tableView:heightForHeaderInSection: UITableView delegate is what you are after. You can find more info here: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html

How do I stop a UIScrollView from bouncing horizontally?

I have a UIScrollView that shows vertical data, but where the horizontal component is no wider than the screen of the iPhone. The problem is that the user is still able to drag horizontally, and basically expose blank sections of the UI. I have tried setting:
scrollView.alwaysBounceHorizontal = NO;
scrollView.directionalLockEnabled = YES;
Which helps a little, but still doesn't stop the user from being able to drag horizontally. Surely there is a way to fix this easily?
scrollView.bounces = NO;
Worked for me.
That's strange, because whenever I create a scroll view with frame and content size within the bounds of the screen on either dimension, the scroll view does not scroll (or bounce) in that direction.
// Should scroll vertically but not horizontally
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scrollView.contentSize = CGSizeMake(320, 1000);
Are you sure the frame fits completely within the screen and contentSize's width is not greater than the scroll view's width?
The checkbox for bounce vertically in storyboard-scrollview can simply help...
That works for me in Swift:
scrollView.alwaysBounceHorizontal = false
scrollView.bounces = false
Try setting scrollView.bounces to NO and scrollView.alwaysBounceVertical to YES.
Whether or not a view scrolls (and bounces) horizontally depends on three things:
The content size
The left and right content insets
The width of the scroll view -
If the scroll view can fit the content size plus the insets then it doesn't scroll or bounce.
Avoid horizontal bouncing like so:
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width - scrollView.contentInset.left - scrollView.contentInset.right, height);
I am adding this answer because the previous ones did not take contentInset into account.
Make sure the UIScrollView's contentSize is not wider than the UIScrollView itself. In my own apps this was enough to avoid horizontal scrolling, except in cases where I got really crazy swiping in random directions (e.g., starting a scroll while the view was still decelerating).
If anyone developing for OS X is looking here, as of OS X 10.7, the solution is to set the horizontalScrollElasticity property to false/NO on the scroll view, like this:
Swift:
scrollView.horizontalScrollElasticity = false
Objective-C:
scrollView.horizontalScrollElasticity = NO
Something to keep in mind: You know there's nothing extra to see horizontally, but will your users know that? You may want a little horizontal bounce, even if there's no extra content to show horizontally. This let's the user know that their attempts to scroll horizontally are not being ignored, there's just nothing there for them to see. But, yeah, often you really don't want the bounce.
My version for webViews, a common solution:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[webView.scrollView setContentSize: CGSizeMake(webView.frame.size.width, webView.scrollView.contentSize.height)];
}
You can disable horizontal bounces like this:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.x < 0) {
scrollView.contentOffset = CGPointMake(0, scrollView.contentOffset.y);
} else if (scrollView.contentOffset.x > scrollView.contentSize.width) {
scrollView.contentOffset = CGPointMake(scrollView.contentSize.width, scrollView.contentOffset.y);
}
}
It resets the contentOffset.x manually and won't affect the vertical bounces. It works...
In my case, i just need to set this line:
collectionView.bounces = false