Remove separator in grouped UITableView - uitableview

I need to make a grouped table view with custom cells. Each cell must have a background image, so that image of one cell will touch the image of the second cell and so on. I've tried to set the separatorStyle to None, but I still get the transparent separator between cells.
Help me, please, remove this space between cells.
Have a good day,
Thanks!

I found that when I set the background image, the separator went away automatically. The problem is that I want it to show up.
Here's what I did:
Create a custom UITableViewCell class. In the respective init method do:
// Create a background image view.
self.backgroundView = [[UIImageView alloc] init];
Then in your controller that manages the UITableView:
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// After all of the cell dequeue/allocation...
UIImageView *backgroundView = (UIImageView *)cell.backgroundView;
backgroundView.image = [UIImage imageNamed:#"your_image"];
}

Related

Decrease Tableview selectable area in ios

1Hi in my project there is a requirement to show table row selection(blue color) only half of the row.Is there any way to do this.
The selected cell should be in blue color and remaining all are in white. Please help me to achive this also.I dont want to reload table because many images are there loading from server.If reload again again it will slow down performance.
[Please see the image after selection the cell should appear like this]
enter image description here
You can set selectedBackgroundView property of UITableViewCell with a view whose half is blue.
In didSelectRowAtIndexpath get cell ..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
UITableViewCell *myCell = [tableView cellForRowAtIndexPath:indexPath];
// add view as per your according to need in cell
UIView * myCellAccessoryView = [UIview alloc] init];
// set frame of myCellAccessoryView as per your need ..
myCellAccessoryView.backGroundColor = // set color as you need .
// and add in cell
[cell.contentView addSubView :myCellAccessoryView];
}
hope it helps you ..
You can use this
UIView *backView = [[UIView alloc]init];
backView.frame = CGRectMake(0, 0, cell.frame.size.width/2, cell.frame.size.height);
backView.backgroundColor =[UIColor blueColor];
[cell addSubview:backView];
This will create a blue color background view.

Prevent dragging of cell to the left in iOS7 tableview editing mode

Screenshot below shows one tableview cell in editing mode after swiping to the left on the row. While in editing mode I can hold the cell and drag further to the left again which reveals this white space (bouncy effect when I let go). I'm setting each cell's background image as follows:
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"CellBG.jpg"]];
I have 2 questions.
Is it possible to prevent this extra dragging so this white area will never be seen? Would like the same behaviour as the iOS7 weather app for example.
Also, any idea why there is thin white line under the delete button?
Thanks
Is it possible to prevent this extra dragging so this white area
will never be seen?
Yes. Put the image on the UITableView's background. Not on the cell. Because if you put the image background on a cell and when you horizontally swap a cell to delete, that cell will move. That is to say the image background will also move. But if you put it on the UITableView, it will not move with the swap. Remember to set UITableView and UITableViewCell's background color to be clear color.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"ReuseIdentifier"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"cellBackground.png"]];
imageView.frame = CGRectMake(0, kCellHeight*indexPath.row, 320, cell.frame.size.height);
[tableView addSubview:imageView];
[tableView sendSubviewToBack:imageView];
return cell;
}
2.Also, any idea why there is thin white line under the delete button?
I think that is Apple's little bug. As you can also find it in the weather app. So never mind that.

Add line to the bottom of last cell

I have UiTableView. Cells on it by clicking change itself height. I need to add custom separator lines. I alwaays add to the top of cell. So all work fine, but last cell haven't seporator line on the bottom, and user cann't see the end of tableview. I try to add next code in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
and then try use it in
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
I create in the begin new UIImageView
#implementation MovieSessionsVC
...
UIImageView *seporatorView;
}
And this my code:
[seporatorView removeFromSuperview];
if (indexPath.row == self.sessions.count - 1) {
seporatorView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"seporator.png"]];
if([self cellIsSelected:indexPath])
seporatorView.frame = CGRectMake(0, 106, cell.width, 0.5);
else
seporatorView.frame = CGRectMake(0, 63, cell.width, 0.5);
[cell addSubview:seporatorView];
}
I use self.sessions.count for number of rows, and heoght of my cells is 64 and 107 when selected
So line appear and work fine, but when I pick up my tableview on maximum it is disappear
If it isonly the last cell where you want to add something to, a line in your case, then it is probalby the easiest to draw the line on top of the footer view. You can create a UIView and assign that to the tableFooterView property of UITableView. That footer may just have a height of 1.0 and is filled with a colour.
You can of course draw a line in drawInRect of that footerView. For doing so you will need to subclass UIView. But I think that some standard UIView with a background colour and a height of 1.0 would do.
Just set the resize property of the separator image same as the image below
The separator image to sit to the bottom on any cell resize.. Make sure the cell resize property is all selected..

UITableViewCell's background image's height won't smoothly follow the row's height

We had create a UITableviewController to list some contents,
We want an effect that the background image view will smoothly expand follow as the row's height changing, but we just got the effect with image changed to the final height of row.
the video is what we got:
http://www.youtube.com/watch?v=v-5TtrpYhl8
in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath, we just add a subview too the cell as below
UIImage *cellBackgroundImage = [UIImage imageNamed:#"cellbg.png"];
UIImageView *cellBackgroundImageView = [[UIImageView alloc] init];
[cellBackgroundImageView setImage:[cellBackgroundImage stretchableImageWithLeftCapWidth:10 topCapHeight:10]];
[cell addsubview:cellBackgroundImageView]
than just set height in the -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath like return 50 or return 250
But there obviously some fault around here, how can I fix it? I had google all around, and some apps do this kind of effect (like "DOOO"), I will appreciate you're answers!
we had try other methods like add UIImageView height changing in a custom UITableViewCell's layoutSubview method, that's work the same as the video above
Thank You for CSmith's answer, we had tried this method for background, but we found our problem is not on background, we'll keep finding our solution, but thank you~~ :)
Refer to UITableView cell with background image
cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:#"cellbg.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:10.0] ];

Cell background incorrectly repeating in UITableViewCell when scrolling

I have a full list that populates a UITableView. This I want to background the one of the cells with a different color and it works initially, but for some reason when I start scrolling the table up and down, it starts drawing more cells with the green background.
Please note that there is always one detailCell.detailTimeLabel.text that's equal to currentTime.
The code I have is:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
... SOME MORE CODE HERE ...
if ([detailCell.detailTimeLabel.text isEqualToString:currentTime]) {
UIView* backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backgroundView.backgroundColor = [UIColor greenColor];
detailCell.backgroundView = backgroundView;
for (UIView* view in detailCell.contentView.subviews)
{
view.backgroundColor = [UIColor clearColor];
}
}
}
Which can be the problem?
Your trying to store data in a tableviewcell. You can't do this because the cells are constantly reused. The background you see repeated occurs because its the same cell being displayed over and over again with different text.
When you dequeue the cell, you need to reset it to blank and wipe out all the previous data. Then you should set the background color only if the data you are putting into the cell has the current time.
As a general rule, you should never refer to data in the cells. If you need to know what is in a particular cell, look at the data at the indexpath within the datamodel itself.

Resources