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

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.

Related

Changing background of UITableViewCells in Edit Mode

I have trouble with a black table view appearing white when swiping left to delete (in my case void) a row.
I tried setting every possible parameter for color in every step all the way from the ViewController down to the Content of the TableViewCell.
I managed to get it darkGray for "selection" with the following in CellForRowAtIndex:
UIView *bgColorView = [[UIView alloc] init];
bgColorView.backgroundColor = [UIColor darkGrayColor];
[cell setSelectedBackgroundView:bgColorView];
So I figure the solution is something like that.
I have a similar setup on iPhone where the TableView is in a TableViewController where the issue does not occur. In this particular situation the TableView is in a regular ViewController.
Screenshots attached. Please advise. Edit: Note that the white space is not a button that appears next to the Void-button. It's white space that changes size according to how far your drag the cell. If you release the cell the white space disappears entirely, but the bounce reveals the white space.
Swiped left (in motion):
Swiped left (released):
Unswiped:
Wow - it turns out I only needed to implement the following method:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor blackColor];
}
Ironically I searched high and low for a solution, only to find it 15 minutes after I ask. It's been bugging me for weeks.
Ah, well, maybe someone else stumbles across this problem.

UITableViewCell backgroundView not stretched

I'm trying to set a stretched background picture on the back of a UITableViewCell.
It's a common question, answered many times, so I'm doing it the "standard way" :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
UIImage* bgImg;
bgImg = [[UIImage imageNamed:#"menu_bg_selected.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 1, 0)]; //top/left/bottom/right
cell = [tableView dequeueReusableCellWithIdentifier:#"mycell" forIndexPath:indexPath];
[cell setBackgroundView:[[UIImageView alloc] initWithImage:bgImg]];
return cell;
}
If I simply try this, I obtain a tiled background.
After reading several similar questions/answers, I did try :
Forcing scale of the background View : cell.backgroundView.contentMode = UIViewContentModeScaleToFill;
Force resizing of background view : cell.backgroundView.clipsToBounds = YES;
Set autoresize of the mask : cell.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Trying for force the frame size of the background UIImageView
It appears that my background picture is partially stretched up to a predetermined size, then tiled (not enough reputation yet to upload images, sorry ...) :
vertical stretch is partial and doesn't use full height
horizontal stretch is partial and doesn't use full width
The background picture is a 6x3 pixels image (with a blue vertical line on the left, a dark gray back and a light gray horizontal line at the bottom).
What am I doing wrong ?
Thanks for your help !
[Edit]
In fact the problem doesn't seems to be a UIEdgeInsetsMake problem.
When using bgImg = [UIImage imageNamed:#"menu_bg_selected.png"]; the background image is still not filling the complete cell background.
This code will work for UIImage.
UIIMage *bgImage = [[UIImage imageNamed:#"menu_bg_selected.png"] stretchableImageWithLeftCapWidth:15 topCapHeight:15];
I believe the problem comes from
UIEdgeInsetsMake(0, 5, 1, 0)
Basically you say i want a stretchable image but i don't want the bottom line to stretch neither the left border. That does not make any sense. Your edge insets must leave some stretchable parts. For instance if your image is 6x3 you could have :
UIEdgeInsetsMake(1, 2, 1, 2)
However you might want to redesign your image before.
Allright, I got it !
The problem was that my background picture was only partially stretched and then tiled in order to fill the complete cell (whatever the UIEdgeInsetsMake parameter was).
I succeeded by using : resizableImageWithCapInsets and specifying the resizingMode argument.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
UIImage* bgImg;
bgImg = [[UIImage imageNamed:#"menu_bg_selected.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 1, 0) resizingMode:UIImageResizingModeStretch];
cell = [tableView dequeueReusableCellWithIdentifier:#"mycell" forIndexPath:indexPath];
[cell setBackgroundView:[[UIImageView alloc] initWithImage:bgImg]];
return cell;
}
Thanks to all for your suggestions !

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] ];

Remove separator in grouped 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"];
}

IOS uitableview cell selected background

I have a UItableview in my IOS app with some information in it. I changed the Selected background color to clearcolor using the following code:
UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:[UIColor clearColor]];
[cell setSelectedBackgroundView:bgColorView];
[bgColorView release];
There is text and 2 images in the cell, I've build this using CGRectMake.
But When I select and hold a table cell the the images disappear behind what looks like a white background.
As you can see I'm holding the "Dacnusa sibrica" cell, how can I fix this?
If you want to disable the blue selection of cells you can also set the cell's selection mode instead of modifying the background:
cell.selectionStyle = UITableViewCellSelectionStyleNone
This simply disables the blue selection when tapping the cell but still allows the cell to be selected (and thus handled by code).
With Auto layout it is possible to define Selection=None (default is gray) in the Interface Builder.
have you used [cell.contentView addSubview:image]?
use [tableView deselectRowAtIndexPath:indexPath animated:YES];
for deselecting the cell

Resources