How can I get Rectangle UITableViewCells in an iOS grouped UITableView - objective-c

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.

Related

Design tableViewCell( overlaps table view cell)

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!

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 do I accommodate all the information in one table cell in my iphone application?

In my table cell I have long line of information and because of that I'm not able to show all the information properly. I tried to make the table cell's hight big but that didn't help.
below is the image of the table cell where you can not see the rest of the information.
Thanks
Mayur
You can take Custom cell and inside the same,take UILabel with the property of word wrap with Linebreakmode.Remember to take numberOfLines to 0. Hope that Helps you.
You Can Create a CustomCell inheriting UITableView class and set the size of the cell to the size of custom cell and to get multiple lines you can also set linebreakmode :
lblName.lineBreakMode = UILineBreakModeWordWrap;
lblName.numberOfLines = 2; //Specify Number Of Lines

UILabel object overlaps UITextfield in custom table cell after changing text property

I have specified a custom cell containing a label and a text field in a nib file.
When I change the text property of the label and adding three of those cells in a section of a table view it looks like this:
When I don't touch the text property and simply adding the cell out of the nib file "as is" it looks like this
Well there still remains the question why the textfields right edge moved, but that is not the main problem. Can somebody tell me how I have to configure the label to avoid that nasty behavior when changing the labels text?
Change the frame of your UILabels. Now it looks like they are about 280-300px wide. Change it to something less, 120 for example.
yourTextField.frame = CGRectMake(0, 0, 120, 30);
or some other numbers. Play with it.
Hope it helps
P.S. some code would be nice
Aaaah the great mysteries of autoresizingMask. Do it like this:
Resize your labels width and can always change label background to clear
yourLabel.backgroundColor=[UIColor clearColor];

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.