add finishing separator on uitableview - iphone

I have a custom separator style (fairly simple):
[[UITableView appearance] setSeparatorColor:SOMECOLOR];
Now I want to have my tableview finish with a separator. Currently separators only appear between two cells, but I want to have a separator at the end.
see here:
any ideas how this could be done?

I usually make my own separator inside the table view cell. I do this with a UIView that spans the width of the cell and is 1 or 2 points high.
In your case, if you want the system separator, you would have to add a custom cell at the end which is all transparent and 1 point high. UITableView would then add the missing separator.

I understand it you want a separator at the end as well? You can add a footer view to achieve this effect.

Make a footer view with height of 0.0001. To do so simply implement the following tableview delegate method :
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.001;
}

Related

Override tableView.separatorStyle for a single cell or section

I'm trying to set the tableView.separatorStyle to UITableViewCellSeparatorStyleNone for a single section (or row, I suppose), but allow it to be set to the default for every other section.
As an example (of the unintended behavior):
While the rows at the bottom (and top) of the image should display the default gray line surrounding each section, for this particular section, even though I have set the backgroundColor of the cell to [UIColor clearColor], I would also like to remove the separator from this particular section.
There don't seem to be any delegate/datasource methods that allow overriding this on a per-section basis. The documentation for the separatorStyle property mentions:
UITableView uses this property to set the separator style on the cell returned from the delegate in tableView:cellForRowAtIndexPath:.
So it sounds like it's applied after I've built my cell, and the setter is only at the UITableView level, it is not visible at the ..Cell level.
the separatorStyle property can't be used for a specific cell. It will be used for all the cells. If you want to add separators just for some cells, add a UIView inside the cell's vie that will act as a separator and set the separatorStyle to UITableViewCellSeparatorStyleNone.
In cellForRow.. you can check the cell that will be provided to the table view and decide if the separator should be visible or not.
Just set a custom separator inset of 1000 for cells that you don't want to have separators.

How to hide this part of uitableview

I designed a uitable view like in the image below , I want to hide the part under the second section , which I write on it (<- I want to remove this part ->)
any suggestion to do that
If you coppied the code from someone, this element is the fotter view for the second section. Look for the method:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
end erase it. It should be out.
You can try creating the table with specific height in the Interface Builder or:
UITableView* pTable = [[UITableView alloc] initWithFrame:(CGRect)];
Maybe you can also specify that scrolling is forbidden in order to show the contents that you want:
pTable.scrollEnabled = NO;
You might want to implement tableView:heightForFooterInSection: and tableView:heightForRowAtIndexPath: and return heights for the footer of the current section and header of the next section to reduce the gap between the two sections. This of course, if there are sections are the current section. If there are no more sections, then you can just reduce the frame size.

How to make text in a UITableViewCell wordwrap?

I have a grouped UITableView with a few sections. The text in some of the cells can get quite long, I was wondering how I could make the text word-wrap?
eg
textLabel.numberOfLines = 0;
You can set this to a fixed number of lines if you prefer. It may be a good idea to set the lineBreakMode, and you will probably need to implement:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
using:
NSString sizeWithFont:constrainedToSize:
You'll have the specify the number of lines the text will use.
Setting it to zero will wrap it automatically.
cell.textLabel.numberOfLines=0; // line wrap
set numberOfLines > 1 on your label and set an appropriate lineBreakMode as well. You might need to modify the frame of the label to have enough space. You can do this in tableView:willDisplayCell:forRowAtIndexPath: of your table view delegate.
It looks like this question Custom Cell Height, right? I don't really get what word-wrap do, but I assume that you want to change the cell size according to the text length, is that right? So you can look at the above question and answer

UItableview returns more row?

i have done like
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
tableview is in UITableViewStylePlain.but it shows correctly 3 data on 3 tableview cell.but after that there is empty tableview cells ...but when i declared UITableViewStyleGrouped, it shows only 3 tableview cells... perfectly...what i have to do disappear empty tableview cell
in UITableViewStylePlain..any help pls?
Your table contains 3 table cells and those cells beneath it are not empty table cells. The row seperators are just drawn based on the previous row height giving the impression that there are more cells than you actually specified.
You could set the separatorStyle of the table view to UITableViewCellSeparatorStyleNone, either in code or in Interface Builder. But doing so disables the seperators all together, so you would have to draw some kind of separator yourself in your cells if you still wanted a grafical separation between the actual cells.
Another option would be to set the color of the separator to the color of the background of the table.
I myself would not worry about this if you're application has a standard table look, as it's default behaviour & users should be used to seeing that. Altough I must admit that I have set the separatorStyle to none in a previous project, because the table had a look that deviated from the standard table look. I did have to draw a fine separator line at the bottom in the table cell.

Best (Any) way blend tableview section header onto top of a grouped tableview

I'd like to add section headers to my grouped table view's sections but I'd like them to appear seamless (see image). The default, as we're all well aware of, is rounded top corners on the first row of a grouped table view cell so it ends up looking like crap when you merge them.
Any way to specify when indexPath.row = 0 that the UITableViewCell should use row style "middle" or something like that?
If not then what are my options? I guess I could scratch the section header and use Row 0 as a quasi-header then push my array data +1 to fill the rest of the table? I'd rather not roll my own from scratch...if possible.
Sample Table http://img35.imageshack.us/img35/8181/sampletable.png
Edit:
"Crap" looks like this:
alt text http://img25.imageshack.us/img25/9748/crapsection.png
Don't do what you're doing, it's against HIG
Ok, ok, I'll tell you how to do it:
You're going to want to do your own cell background views. The default grouped one is not what you want.
When a tableview asks you for a cell, set its backgroundView and selectedBackgroundView to something that looks appropriate for its place in the tableview.
Usually, this means a UIImageView with the appropriate image, though you can go wild here with a custom view, but there are gotchas.
So in your case, you would do
if (indexPath.row > sectionRowCount - 1) {
//Not the last row
//Put in the middle background
} else {
//Put in the end background
}
Then you'll want a custom table section header, but that's pretty easy.
In your case, you probably won't have to worry about when there's just one row, so that makes things even easier.
Take a look at the tutorial here:
cocoa with love basically what you need is 3 different images. One for the top row, one for the bottom, and a 3rd for the middle rows.
You could also not use the section header, but instead use a custom cell as the first cell of the section. So when ([indexPath row] == 0), return a custom cell that is the "header" and then return the "regular" cells (offset by one row) for the rest. You'll also have to make adjustments to the numberOfRowsInSection function to return +1.