How to make table cell separator to our desire view - iphone

Hi i want to set a table cell seperator to the following fashion is there any coding to
make this manually

You can't.
You can, however, hide the cell separator and add the view you want at the bottom of each cell.

You can achieve this by using background image of cell. Make a image for cell with footer black line and hide the cell separator so it will look like above image.

You can set the cell separator style to none and add an image to the custom cell.

set the section footer/header view as your desired separater view and set cell separater as none

in the following delegate method,
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
[cell setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[cell addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"yourImg.png"]]];
}

Related

How to update UITableViewCell drawing

My app displays some news in a UITableView. For each news-topic, the background color of the UITableViewCell is different (added a UIView in my custom cell).
So far, it works. But If I press on a UIBarButton to deselect one news-category, the content changes, but the background stays the same as before.
The color does not change, because the cell does not reload again after button click.
Any ideas?
Thank you!
You can set the color for the cell in (as per your logic):
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
This will make sure the color is set every time the cell is displayed.
In your cellForRowAtIndexPath method, make sure that you're setting the color of the UITableViewCell.
Also, use [tableView reloadData];

Background image does not extend to accessory view background in table view cell

I'm using the code below to set a background under each cell in my table view. It works fine but there's a white space under the accessory view on the right side so the background does not cover this area. Any idea on how to fix this issue ?
(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"cell-background.png"]];
}
Thx for helping,
Stephane
You probably want to create a custom cell. Please see Apple's documentation about contentView.
To add subviews to a cell to customize it furthur please see this. It also has a section on how to create custom cells from XIBs.

Delete Button in UITableView

i want a Delete Button in my UITableView like in die AdressBook when editing a contact.
Is this a custom cell, or a UIButton?
To make such button you can do following:
Make your UITableView style Grouped.
Add +1 section to your table.
Say to your table that it is one cell for last section
Just return custom cell (with red background and appropriate label) for last section
If you implement the Delegate method's for edit the tableview
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
And than implement the DataSource method
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
For allowing to get that delete button when you swipe a cell use the
Cell Editing Style : UITableViewCellEditingStyleDelete
// Edit: Wrong answer.
Do you mean the Big one at the bottom or with the sign on the left?
use....
firstly use
[btn removeFromSuperview];
and
[tblobj reload];

Update UIViewTableCell's background when accessory URL is clicked

In the tableView:accessoryButtonTappedForRowWithIndexPath: selector, I want to update the backgroundColor of the cell.
I can get the UIViewTableCell using cellForRowAtIndexPath: but I'm not sure how I can update its background color. The code beliw doesn't seem to work.
[_tableView beginUpdates];
cell.backgroundColor = [UIColor grayColor];
[_tableView endUpdates];
Any suggestions?
I would first try [cell setNeedsDisplay];.
Also beginUpdates and endUpdates is meant to be used when you are going to be inserted/deleting rows etc. so I don't think it's necessary here.
Background colors on cells is a tricky thing because the table view will do some magic behind the scenes to handle cell selection. To get reliable behaviour you need to set the cell's background color in this UITableViewDelegate method:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
A table view sends this message to its delegate just before it uses cell to draw a row, thereby permitting the delegate to customize the cell object before it is displayed. This method gives the delegate a chance to override state-based properties set earlier by the table view, such as selection and background color. After the delegate returns, the table view sets only the alpha and frame properties, and then only when animating rows as they slide in or out.

How can set the background view of a UITableViewCell to the selected background when it is not selected?

I created a custom implementation of a multi-selectable table view. Multiple rows can be selected programatically. The only part I haven't been able to figure out is how to programatically set the background view of cell to the default system cell selected color/pattern.
Does anyone know how to do this?
Thanks!
Could you please post your method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Same code can help to understand the problem :)
Are you asking how to programatically select rows?
If so, then use the ‘selectRowAtIndexPath:animated:scrollPosition:‘ method call, or create the cell with
cell.selected = YES;
For the first cell, set it to selected as normal. For other cells, get the class of the backgroundView of the first selected cell, instantiate a new object of that class, and assign it as the background view.
otherCell.backgroundView = [[[[[firstCell backgroundView] class] alloc] init] autorelease];