UITableViewCell's detaiTextLabel overlaps with custom subviews - iphone

I want to customize UITableViewCell by adding UILabel and two UIButton as its subview.
The cell style will be UITableViewCellStyleSubtitle and these three items would have to
next (on the left) of detailTextLabel.But when i do this, detailTextLabel overlaps with these items and display clipped or partial subviews.
Any way to handle out this without subclassing UITableViewCell if possible.
Thanks.

do you want to display something with detailTextLabel? If not you could try to hide it.
cell.detailTextLabel.hidden = YES;
otherwise you could add another Label at a better position which displays your detailText

Related

Custom UITableViewCell with Storyboard

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.

how to slide UILabel in uitableviewcell when swipe to delete is used

I have a custom uitableview with a UILabel to the right of the cell as shown below
I have enabled swipe to delete, but when the button appears the UILabel is covered, I am guessing this is because my custom tableviewcell has not been informed about the delete button..
I am wondering how I go about moving the UILabel to the left of the delete button when the swipe is detected.
This is how you would do it if you create the cell in a xib.
You create a view the same size as the cell and put all of your labels inside it. Create an outlet for this view. Then in the .m of the customCell you add the view to the contentView.
[[self contentView] addSubview:cellView];
Then, in the xib add struts so that the labels stick to the edge of whatever side they are nearest and you should be good to go!

UITableViewCell subclass - how to add a button to some rows

I have a UITableViewCell subclass that has 3 labels and sizes and positions the labels based on the text length. When selected all rows perform the same function. I'd like some rows to also have a detail view associated with them. So I want to add a UIButton to a few rows, but I'm not sure how to do it.
Should I create a UIButton member of the UITVCell subclass and in layoutSubviews if the button is not nil I can make room for it?
What would cellForRowAtIndexPath look like? Do I need two reuse identifiers ? One for button and one for no button? Or just create the button and the cells that have buttons will automatically detect the button in layoutSubviews and make room for it?
I can't find any examples online of someone doing this without using XIB..
EDIT - So I added the detail disclosure button as suggested below, I can detect that my cell has an accessoryType, but the accessoryView width and height are garbage.. I need a width and height because right now the accessory is on Top of my row text since I'm not accounting for it in my layoutSubviews code..
// CustomTableViewCell.m:
- (void)layoutSubviews {
// I need a width / height here so I can accomodate the accessory button.
if ( self.accessoryType != UITableViewCellAccessoryNone ) {
NSLog(#"accessory! %f %f",self.accessoryView.frame.size.width, self.accessoryView.frame.size.height);
}
}
You don't need to add a UIButton to rows that have a detail view -- just allow them to have a disclosure button (note: button, not indicator!). A disclosure button, when tapped, typically shows a detail view for that cell.
To enable the disclosure button for a certain cell, do the following in the cellForRowAtIndexPath method:
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
More details here:
What's the difference between an Detail Disclosure Button and an Disclosure Indicator?

How do I hide the UITableViewCell border for a custom cell in a group tableview?

What I am trying to do: I want three buttons side-by-side in a tableviewcell just like in Contacts app.
What I've done: I have a custom tableviewcell with three uibuttons in it. I've set the background color of the tableviewcell to be transparent.
What I can't figure out: The tableviewcell border is still there! Everything looks great except for the border floating around the 3 buttons.
Am I doing this completely wrong? Or is there a simple way to remove/hide the border?
Thanks!!!
Don't put these in a cell. Simply create a custom UIView that contains the three buttons, and use that view as your Table's footer:
[myTableView setTableFooterView:customUIViewWithButtons];
Good luck!
What about if I want my transparent cell in the middle?

how to create a cell view which has a button and a "shorter cell" like contacts app?

I haved tried to create a view with a UIButton and a tableView Cell,
then I set the header view to be this view.
However,the cell in the header is not rounded-rect, besides,how to handle the cell's event,when user click this cell.
I haved tried to use custom cell also, but how to create a button and a shorter cell in a row?
when you select the cell,will not affect the button state?
thanks.
You can fake this in a number of ways. The simplest is to layout a rounded rectangle UIButton in your header, and turn off userInteraction for it so that it's just decorative.