Horizontal UITableViewCell iphone - iphone

I want to scrolling Horizontal UITableView in iphone ? or How to create custom Horizontal scrolling UITableViewCell and added with UITableView ? Please i really need this.Or anyother controls that shows 10 columns per row in UITableView .
My data size is out of the screen for each row i dont want to fold it .So how can i increase the tableview size horizontally ? Is it possible ? I want to show 11 columns per each row in UItableview. Now i can able to create 5 columns per each row.
Thanks in advance.... If possible give some sample code .

You have lots of questions at once, you should dice them and separate them so that we won't be confused.
Anyhow for the Horizontal Table View, you can subclass UITableViewController
In the viewDidLoad, apply 180 degree rotation.
E.g.
- (void)viewDidLoad {
// Rotates the view.
CGAffineTransform transform = CGAffineTransformMakeRotation(-1.5707963);
self.tableView.transform = transform;
// Repositions and resizes the view.
CGRect contentRect = CGRectMake(0, 90, self.view.frame.size.width, self.view.frame.size.height);
self.tableView.frame = contentRect;
[super viewDidLoad];
}
Of course you still need to add some adjustments to the cells inside as you see fit.

I don't know if it's possible to do it with just an UITableView.
But you can try putting the UITableView in an UIScrollView :-)
Then you would have an horizontal scroll ^^
Good Luck !

Related

UITableView vertical scrolling issue

I have a frustrating issue with UITableView vertical scrolling. I have an (apparently) functioning UITableView (table rows displayed properly, I can select rows and the proper action is performed, etc).
However, I cannot fully scroll to the bottom of the view. I realize that this question has been asked many times, and I have tried to implement the suggestions given in earlier answers, to no avail. I suspect a fundamental misunderstanding on my part.
I realize that the frame size needs to be larger than the contentSize for the tableView to scroll properly and I have tried to ensure that. Note that I have just picked a small horizontal contentSize for debugging purposes. I am sure it is something simple...
Here is a code snippet that shows what I am doing.
self.testTable= [[UITableView alloc] initWithFrame:self.view.frame
style:UITableViewStyleGrouped];
self.testTable.delegate=self;
self.testTable.dataSource=self;
self.view = self.testTable;
NSLog(#"table: Width: %f height %f ",self.testTable.contentSize.width,self.testTable.contentSize.height);
self.testTable.contentSize=CGSizeMake(320,200);
NSLog(#"table: Width: %f height %f ",self.testTable.contentSize.width,self.testTable.contentSize.height);
My NSLog calls return this:
2013-04-02 13:23:53.332 TestSet[32358:907] table: Width: 0.000000 height 0.000000
2013-04-02 13:23:53.333 TestSet[32358:907] table: Width: 320.000000 height 200.000000
For what it is worth:
#property(nonatomic,strong)UITableView *testTable;
Any advice gratefully received.
Update - am trying this in landscape orientation
It doesnt depend on the content size but it is because your frame is not correct.check frame of tableview is proper.Issue will be there in height of tableview will be out of the view and the scroll will bounce when the table scroll reaches the bottom
make the frame of tableview using [tableview setFrame : CGRectMake(x,y,width,height)];
make
Remove
self.view = self.testTable;
self.testTable.contentSize=CGSizeMake(320,200);
add
[self.view addSubview:self.testTable];
USE THIS
self.testTable= [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
self.testTable.delegate=self;
self.testTable.dataSource=self;
[self.view addSubview:self.testTable];
I solved my own problem. All of the above was being done in the view controller initWithNibName, instead of viewDidLoad. A silly mistake.
I thank everyone for their kind assistance, however.

UICollectionViewCells with UICollectionViewFlowLayout - strange layout happening

I am currently testing in xcode a UICollectionView with just one horizontal row like a kinda cover flow. Basically I have my own Custom Cell class and xib file for the cell and then on each cell I am adding another UIView with a xib. In case you are wondering why, it is so I can add different UIViews to the cell. Right now I am only adding one.
Edit I have followed the WWDC 2012 video on creating a linelayout of a UICollectionViewCell with one difference. Instead of the cell in the middle getting bigger all the other cells get smaller.
Everything below is new to my question.
-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSArray *array = [super layoutAttributesForElementsInRect:rect];
CGRect visibleRect;
visibleRect.origin = self.collectionView.contentOffset;
visibleRect.size = self.collectionView.bounds.size;
for (UICollectionViewLayoutAttributes *attributes in array){
if (CGRectIntersectsRect(attributes.frame, rect)) {
CGFloat distance = CGRectGetMidX(visibleRect) - attributes.center.x;
CGFloat normalizedDistance = distance / ACTIVE_DISTANCE;
if (ABS(distance) < ACTIVE_DISTANCE) {
//THIS WOULD MAKE THE MIDDLE BIGGER
//CGFloat zoom = 1 + ZOOM_FACTOR *(1- ABS(normalizedDistance));
//attributes.transform3D = CATransform3DMakeScale(zoom, zoom, 1.0);
//attributes.zIndex = round(zoom);
} else {
//THIS MAKES ALL THE OTHERS NOT IN THE RECT SMALLER
CGFloat zoom = 1 + ZOOM_FACTOR *(1- ABS(normalizedDistance));
attributes.transform3D = CATransform3DMakeScale(zoom, zoom, 1.0);
attributes.zIndex = round(zoom);
}
}
}
return array;
}
The problem can be seen in the attached image.
Pink = Collection View Size
Brown = Cell size
Green = Cells Content size and an attached xib to the content size.
The problem I THINK I have is with the layout. When the sell is dequeued it is made smaller by the above code. Then when it is reused the CELL gets bigger again but the content view does not.
I have tired to manually set the frame of the content view but that does nothing.
UPDATE 1: This also only happens when I add a xib to the Cells content view. If there is no subview to the content view then there is no problem
UPDate 2: It appears that the subview of the cell, my xib is not resizing. I have tried to manually change its frame size but the only place this helps is in the cells drawrect method which feels like a hack to me.
reused cell not able to redraw itself so give call to
-(void)setFrame:(CGRect)frame {
[super setFrame:frame];
[self setNeedsDisplay]; // force drawRect:
}
from cellForItemAtIndexPath of the UICollectionView.
also have a look at this link
and this question
My answer is very specific and I am not sure it will help anyone.
The problem was that I had a constraint on the bottom of the grey view. After I changed this constraint to a less than or equal too then for some reason it worked.
Now I know this does not explain why it was not happening to every cell but it fixed my problem.
As such Harsh's answer might also be worth looking at if you have landed here after doing a search.
Edit: there also appears to be some bugs in the 6.0 UiCollectionView controller which seem to be fixed in 6.1

UIScrollView problem, scrolls just on one side

I'm fairly new to programming, and I have looked for an answer for a very long time. There are some posts about it, but nothing has solved my problem. I have a UIScrollView view that I get from the nib, everything is ok with this, the content length is good and scrolling works, but it just scrolls on the left side, if I try to scroll on the right side it doesn't scroll..
Here is the code,
- (void)viewDidLoad {
[super viewDidLoad];
NSString *descriptionString = _currentBook.description;
CGSize stringSize = [descriptionString sizeWithFont:[UIFont boldSystemFontOfSize:16] constrainedToSize:CGSizeMake(387, 9999) lineBreakMode:UILineBreakModeWordWrap];
_authorLabel.text = _currentBook.author;
_titleLabel.text = _currentBook.title;
_descriptionLabel.text = [NSString stringWithFormat:#"Description: %#",_currentBook.description];
[(UIScrollView *)self.view setContentSize:CGSizeMake(387, stringSize.height +50)];
}
Thanks in advance!
Its hard to understand the problem since we cant see your nib file, but its better practice to put the scrollView on top the view of the view controller, and connect it to an IBOutlet in your view controller.
In order to find the problem I would get rid of the textfields for testing purposes (I think the constrained 9999 might be a problem but I am not sure) and then print and post the frame of the scrollView and the Content size in runtime.I am betting that you will see some issue with the frame of the uiscrollview.
Thanks,
Ok, after copy-pasting and running some tests, I found out the problem.
The problem is in the wording of the question, your problem is not that the "scroll doesn't work on the right side" (As in: you move your finger up and down on the right side of the screen without triggering a scroll), the problem is that the contents, the label itself is going out of bounds, outside of the visible area of the scrollView, and the right-handed side is not visible.
First of all, you should note that the iphone resolution is 320x480 (640x960 for Retina), so you actually have to work with a smaller width (using 387 width will make it go out of bounds).
Second, take in account the x position of the label itself is also affecting the amount of visible text. With this in mind, a more generic code would be:
- (void)viewDidLoad
{
[super viewDidLoad];
// This number represents the total width of the label that will fit centered in
// the scrollView area.
CGFloat visibleWidth = self.view.frame.width - descriptionLabel.frame.origin.x*2;
// Use the number above to get a more accurate size for the string.
NSString *descriptionString = _currentBook.description;
CGSize stringSize = [descriptionString sizeWithFont:[UIFont boldSystemFontOfSize:16] constrainedToSize:CGSizeMake(visibleWidth, 9999) lineBreakMode:UILineBreakModeWordWrap];
// Fill data (why so many underscores?)
_authorLabel.text = _currentBook.author;
_titleLabel.text = _currentBook.title;
_descriptionLabel.text = [NSString stringWithFormat:#"Description: %#", _currentBook.description];
// Also, why didn't you resize the description label? I'm assuming that you forgot this.
// (Make sure that the descriptionLabel number of lines is 0)
CGRect frame = descriptionLabel.frame;
descriptionLabel.frame.size = stringSize;
// Now set the content size, since you're using the scrollView as the main view of the viewController,
// I'll asume that it's using the whole screen, so I'm gonna use the whole width
// of the screen (that's what UIScreen is for).
[(UIScrollView *)self.view setContentSize:CGSizeMake([UIScreen mainScreen].bounds.size.width, stringSize.height +50)];
}
Finally i've found my problem, I've added a uiview programmatically as a subview to some view and then to this View i've added my scroll view as a subview.. And then it would only scroll in the area of my UIView. It was nonsense to do it like this, still a lack of knowledge..
Thank you all for trying to help!

Bottom/Right Alignment for a UITableView

Aplogies, but this is another newbie iPhone/Objective-C question.
I'm working on my first iPhone app which is a simple RPN calculator. I have a table displaying the contents of the stack, and now I'd like to fine tune the display a little bit.
I would like for the last entry in the stack to display at the bottom of the table, with the text right aligned. The right alignment was easy with
cell.textLabel.textAlignment = UITextAlignmentRight;
and I can make the table peg the last entry to the bottom of the view with this code:
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:(stackSize - 1) inSection:0];
[tableView scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
which works great but only when there are more entries on the stack than will fit in the view. When the stack has few entries, they're still aligned to the top of the view.
I've played a bit with altering the height of the cell for the first stack entry such that the first cell fills the whole view and shrinks as new cells are added until there are enough stack entries to fill the view, at which point the cell height is left alone. This seemed promising, but I'm having some trouble getting the "big" cell to bottom align the label. (It's vertical center aligned, by default.)
As I was hacking away at the bottom alignment thing, I began to wonder if I'm making this more complicated than it needs to be. Any thoughts?
I don't know if this is kosher, but you can use view transforms to rotate the table 180° and then rotate each cell 180°. I use this trick to create sideways tables (90° instead of 180°) on an app I'm writing.
Another approach is to resize the table view as you add or remove rows. You update the height and move the table view accordingly. Something like this looks quite OK:
- (void)resizeTableView {
CGFloat tableViewHeight = [self tableView:self.tableView numberOfRowsInSection:0] * self.tableView.rowHeight;
// remember to check the height !!
CGRect frame = self.tableView.frame;
frame.size.height = tableViewHeight;
frame.origin.y = BOTTOM_OF_VIEW - tableViewHeight;
[UIView animateWithDuration:0.3 animations:^{
[self.tableView setFrame:frame];
}];
}
If you are using the default animations for insert and delete, remember to set them to UITableViewRowAnimationNone, otherwise it looks strange.

Determine coordinates of a UITableViewCell while scrolling

My goal is to have the UITableViewCells fade in/out when they are approaching the bounds of the UITableView and about to be covered/revealed.
The approach I have been trying is to get the coordinates of the UITableViewCell during a scroll event. The problem is that every cell seems to be at 0,0. I have tried converting the coordinates to the parent table and view, but they still come out at 0,0.
So in general, if anyone knows a way to get the coordinates, or of a better way to go about fading UITableViewCells in and out based on their position, I would greatly appreciate any advice you may have.
Thanks for your time,
Joel
The first step is to use
CGRect rectInTableView = [tableView rectForRowAtIndexPath:indexPath];
which will report the CGRect of a cell within the tableView. However, this value does not change as the tableView scrolls. It is the position relative to the first row of the table (and not the first visible row). To get the position of the cell on the screen you have to convert it to the superviews coordinate system using
CGRect rect = [tableView convertRect:rectInTableView toView:[tableView superview]];
So the following line does it all
CGRect rect = [tableView convertRect:[tableView rectForRowAtIndexPath:indexPath] toView:[tableView superview]];
Swift 4
// Consider the indexPath at row 1, section 0.
let rectWithinTableView : CGRect = self.tableView.rectForRow(at: IndexPath(row: 1, section: 0))
let rectWithSuperViewCoordinates : CGRect = self.convert(rect: rectWithinTableView, to: self.tableView.superview)
Why not an overlay with a partially transparent gradient PNG in a UIImageView that's less translucent at the top and bottom?
Messing with cell drawing in table scrolling is going to take a big performance hit.
You can call
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;
to get the rect of any given cell. This will contain it's coordinates in the origin struct within the rect.
I suspect the cells are held within 'cell sized' subViews of the UITableView so you are seeing a frame relative to that view.
I don't have an actual an answer for you but, I would suggest checking out UIScrollView's delegate class: UIScrollViewDelegate. It responds to – scrollViewDidScroll: and you can manually work out your offset from that. UIScrollView is a superclass of UITableView.
You can convert points (such as your origin) to another view's co-ordinates using UIView's - (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view method.