I have a cell that I have designed in Interface Builder, and when I enter edit mode, it moves the whole cell to the right to make space for the delete icon, but it pushes all items to the right, not shrink them down. It pushes a UILabel off of the edge of the cell. Also, this is over the move handles. How do I shrink these items down, instead of just moving them.
I've never made a custom tableview cell in Interface Builder. So, I don't know how to solve your problem on Interface Builder.
But if you programmatically add all items into the contentView property of UITableViewCell instead of adding these into UITableViewCell itself, these items would automatically shrink when entering edit mode.
I have a partial solution.
On the custom cell object I've created a IBOutlet to the view that holds all subviews in the cell (myContentView).
This way I can run this code to shrink it:
OrderReviewCell * cell = (OrderReviewCell * )[reviewTable cellForRowAtIndexPath:indexPath];
CGRect frame = cell.myContentView.frame;
frame.size.width = 200;
cell.myContentView.frame = frame;
I've figured that the best place to put this is in shouldIndentWhileEditingRowAtIndexPath but my problem is Where to put the code that returns the cell to its normal state?
Hope it helps and DO let me know when you find the right answer!
Gonso
Related
My goal is to create a custom UITableViewCell which contains 2 UILabels. One is the title and one is the detail. The detail label should allow for 3 rows of text.
So I went on and created a custom table view cell in storyboard. I also created a subclass of UITableViewCell and linked the two together.
I the added two UILabel to the cell in storyboard and placed them where i wanted them to be and linked them to their coresponding outlets in teh subclass. Since the content of the labels varies I wanted to align the text vertically to the top. As I understand the only way to do this is by calling the sizeToFit method on the label. I execute this under in the sub class of UITableViewCell:
-(void)layoutSubviews {
[super layoutSubviews];
[self.detailTextLabel sizeToFit];
}
So far everything seems fine and the text in the detailTextLabel is aligned as it should. Although when i satrt interacting with the cell, for example slide my finger over it so the delete button appears, the detailTextLabel will change size to the size that was set in storyboard. This causes the text to be misaligned. Similar things happen when i select the cell and change to another view and the return to the table view via a tab bar
My question is: Is there any way of creating this custom cell differently using storyboard or is my only alterative to create everything programtically?
Regard, Christian
Maybe you should take a look at this if you still want to vertically align your text in your UILabel without sizeToFit (who will resize it when you will interact with your cell).
About your question, I think you can create your custom cell from a xib file like this.
In Weather.app on iPhone, scrolling past the bounds of the Hourly tableview continues to show the alternating table cells, just without any text inside of them (see image below). I was wondering how I could replicate this look. This question provides one solution, but I was hoping there was a more efficient way then just adding an image of blank cells above my tableview.
Thanks
You can use the headerView and footerView properties of the UITableView. These allow you to specify custom UIViews that will be placed before and after your content cells.
So, you should initialize a UIView with some dummy inner views with alternating colors. The height for this UIView should be equal to tableView.frame.size.height. then just do:
tableView.headerView = headerViewWithFakeColors;
tableView.footerView = footerViewWithFakeColors;
Also, you will also need to change the contentInset property so that these fake header&footer views are only visible when the user is bouncing (with contentInset you can control the point where the tableview starts bouncing)
tableView.contentInset = UIEdgeInsetsMake(headerViewWithFakeColors.frame.size.height, 0, -footerViewWithFakeColors.frame.size.height, 0);
I have a UIScrollView inside a cell but when the cell is selected the view disappears in the background how can I put it back to foreground. Thanks
JVPython
It's possible you aren't properly setting up your UITableViewCell so that selection doesn't cover up the cell contents. Perhaps you are adding the scrollview to the cell directly and not to the contentView of the cell?
The Apple documentation describes the layout of a cell and what happens to those elements when a cell is selected: Table View Programming Guide
Have you tried:
[self.view bringSubviewToFront:myScrollerView];
I'm trying to determine whether a UITableViewCell subclass is in edit mode from a user's swipe (in which case I don't need to indent my subviews) or from the user pressing the "Edit" button associated with the UITableViewController. (In which case I do.)
I know it's possible from a cell's perspective, since the self.textLabel view automatically indents properly. I have tried:
-(void)layoutSubviews {
[super layoutSubviews];
CGRect labelFrame = self.textLabel.frame;
labelFrame.origin.x += 5;
myCustomUILabel.frame = labelFrame;
}
But my custom label does not properly indent. (Though the self.textLabel view does?)
I would like to avoid the following:
Providing the cells with a reference to the parent table.
Overriding methods in the UITableViewController class to let the cells know whether they are being edited individually or the entire table is editing.
You can override willTransitionToState: in your UITableViewCell subclass. When the "Edit" button is pressed the state will be UITableViewCellStateShowingEditControlMask(=1) and when swiping it will be UITableViewCellStateShowingDeleteConfirmationMask(=2).
You should not be doing the indentation manually. The UITableViewCell will do it for you!
All you have to do is make sure that you add your subviews to 'contentView' of the UITableViewCell. This is the reason why self.textLabel indents properly as you have identified.
Look at the documentation of contentView property for a UITableViewCell:
The content view of a UITableViewCell object is the default superview for content displayed by the cell. If you want to customize cells by simply adding additional views, you should add them to the content view so they will be positioned appropriately as the cell transitions into and out of editing mode.
I'm trying to create a cell on a tableview which doesn't go "all the way" from left-to-right of the screen.
Basically, what I need is a cell which (as usual) starts on the left side of the screen, but with a given width, creating a free space on the right.
Is there any way of doing it? I wasn't able to find any example.
Sorry for the eventually noob question, and many thanks in advance.
In older versions of the SDK this was possible using the initWithFrame:reuseIdentifier:method, however this is deprecated since 3.0, so that you should create the UITableViewCell using the initWithStyle:reuseIdentifier: method.
You can access the frame of the UITableViewCell using the frame property and change it's size:
CGRect frame = cell.frame;
frame.size.width = 123f;
cell.frame = frame;
For indentation on the left side you can simply use the UITableViewDelegate method tableView:indentationLevelForRowAtIndexPath:
You can also add a specific subview to the UITableViewCell on the right side (an accessory view) using the accessoryView property of the cell:
UIView *view = ...
cell.accessoryView = view;
(If the value of this property is not nil, the UITableViewCell class uses the given view for the accessory view in the table view’s normal (default) state; it ignores the value of the accessoryType property. The provided accessory view can be a framework-provided control or label or a custom view. The accessory view appears in the the right side of the cell. UITableViewCell Class Reference)