Design tableViewCell( overlaps table view cell) - objective-c

How to design this table view cell..
Cell overlaps the another cell.
Please help me

Set the y offset of the pictureImageview to be negative i.e -50.0f or so, the image will appear as starting from the cell above.

I just tried AppleDelegate's solution but didn't work, because the top of every image is cut, maybe because it is beyond the cells bounds, even with clear color for background.
A different approach would be to believe that it's just a visual effect, and cells are not overlapping. This is possible by giving a different height for every cell with next code :
- (CGFloat)tableView : (UITableView *) tableView
heightForRowAtIndexPath : (NSIndexPath *) indexPath {
// RETURN A DIFFERENT HEIGHT FOR EVERY CELL DEPENDING ON INDEXPATH,
// INCREASING IT GRADUALLY.
}
In the next image, the black lines look like cells' top border, but maybe that's the effect, and the real limit is the red line :
Thinking this way, only the first cell requires a special treatment for the green titles.

Try setting constraints in storyboard and then keep the UIImageView's size/frame of image same when the image is set to UIImageView. Good Luck!

Related

Wrong UITableViewCell height for some cells at first loading

I am using UITableViewAutomaticDimension to calculate height for my table view cell. It works fine for me. But for some cells, the height returned is 44 rather than dynamically calculating height. But on scrolling up an looking back to the same cell, the height is recalculated perfectly. So I guess I do not have any faulty constraints because, after I scroll and correct all cell heights manually, no constraint breaking warning are shown afterwards.
Edit
The below given is the screenshot of image(got messed up when cropped, but can see the issue from the profile image.). The first cell height is calculated correctly. But the rest are faulty.
I have added the following and everything worked fine.
(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
In my case it was something wrong with layoutMarginsGuide top and bottom anchor. I use it for cell subviews and set preservesSuperviewLayoutMargins = true for its subviews. This caused the mistake when system tried use systemLayoutSizeFitting to calculate cells height first time.

Vary table view cell height based on text

I have a table view with a few cells. The text that fills up the cell is unpredictable (based on the result of an API request). What I want to do is adjust the cell's height based on if the cell's text is too lengthy for the cell (e.g. the cell adds '...' to the text).
That way whatever the result/text and gets presented into a table view cell is always fully shown.
I would prefer not to implement the heightForRowAtIndexPath because I would have to implement a lot of code to do so.
UPDATE:
When I say "I have a lot of code to do so", I mean I literally have a lot of code parsing out requests and checking for conditions and performing algorithms and plus I have many table views. Just moved that stuff to another method and Im off to go!
Could you point me to any resources demoing this, do you know how to do this?
You must implement heightForRowAtIndexPath to vary the height of your table rows, but there isn't necessarily alot of code needed to calculate the height.
Use NSString:sizeWithFont:constrainedToSize to calculate the cell size needed.
//szMaxCell contains the width of your table cell, and the maximum height you want to allow
// strCellContents is an NSString containing the text to display
CGSize szMaxCell = CGSizeMake (tableView.frame.size.width - 20,999);
UIFont *font = [UIFont systemFontOfSize:12]; // whatever font you're using to display
CGSize szCell = [strCellContents sizeWithFont:font constrainedToSize:szMaxCell lineBreakMode:UILineBreakModeWordWrap];
szCell contains the size of the label. You'll use this size both to calculate the frame of your UILabel in your cellForRowAtIndexPath, as well as in your heightForRowAtIndexPath.
Use heightForRowAtIndexPath. It shouldn't be lots of extra code. Just get a reference to the object you are populating your cell with, check out the length of that text value and return the height you need. That is exactly what that delegate method is designed for.

How can I get Rectangle UITableViewCells in an iOS grouped UITableView

I have a UITableView with style: "Grouped"
By default, the iOS gives me rounded cells, with a white background and a grey separator.
How can I configure the table so that, for only one section of cells, the cells are rectangular (no border radius) and have no separator? - I wish to use a custom background image on these cells.
Thanks in advance -
bo
You can make them squared off by creating a dummy cell for the first and last cell and setting the row height to 0 for those cells in tableView:heightForRowAtIndexPath:.
You can set the seperator to None and clearColor in the inspector section of the storyboard in order to get rid of the seperators.
Then you can just create a custom background image using backgroundView for the cell in your cellForRowAtIndexPath::
UIImageView *customImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"yourimage.png"];
[theCell setBackgroundView:customImage];
You can use two kinds of UITableViewCell in the table, original for the standard cells and customized subclass with overridden drawRect to draw the other cells depending on indexPath.

How to detect how many cells are visible in a UITableView

My table view covers part of the view. If I have 20 objects, I am displaying all of them in a tableview. But I want to know that how many cell are loaded that are visible to the user.
(i.e. first 5 cells data is visible for me: when I scroll down, the remaining cells will load. Here I want to know without scrolling how many cell are loaded.)
Is this possible?
You can use [tableView visibleCells] count], which returns numbers of the table cells that are visible, if I understand correctly what you want.
The below code will give you the array of indexpath of cells currently visible
NSArray *visiblePaths = [self.tableView indexPathsForVisibleRows];
after getting the index path you can easily access the cell at a particular indexpath
Its usually : (tableView's height / cell row height ) + 1
Can you take the size of the visible part of the table, and then the size of one cell, and divide them to know how many of them fit in the screen?

set scroll last UItableview cell

when I scroll position end of UItableview the last UItableview row seems half. how can I show the last row fully and how can I detect scroll to last row?
I don't know what you mean by "seems half". I suppose that means only half of the cell is shown? Make sure the frame of the whole table view is visible first.
If you want a cell to appear within the bounds of the table view, use
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:? section:?]
atScrollPosition:UITableViewScrollPositionBottom animated:YES];
I think there is something (like a tabBar) at the bottom of your screen and it is overlapping the UITableView .. am I right, am I right?!
Just make the frame of the UITableView 48 pixels shorter. That's the average size of a tabBar..
Or perhaps you have not taken in account that the bar at the top (the status bar) also counts, which is about 15 pixels high. In that case, take 15 pixels of the height of your UITableView's frame.