I'm creating a custom UITableViewCell from an xib. However, the cells don't automatically fit the same height I set in the xib file. Is there a way to get the height of the xib in the heightForRowAtIndexPath so that I can accurately set the height without having to hard code it?
Selecting the UITableView on the storyboard, or view etc, within the interface builder you can set the cell height to match your custom cell nib's height.
Go to the Utilities panel and select the tab as highlighted in blue in the picture below. Set the row height here.
I hope this helps with what you are looking for.
Cheers
You can also use this delegate method of table View
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Height same as your XIB of cell
}
Related
I have a uitableview cell. I want it to expand and show a lot of text. I set it up with autolayout and constraints. It looks right, but when I run it only shows up to two lines. I don't understand. Can someone point me in the right direction? Thank you.
Here's a link to an image of the setup: https://docs.google.com/document/d/1V8jetMrVDK4ebaconz9PL0y3DnJUqXmPkfyhK-0Nhbc/edit?usp=sharing
From the 2014 WWDC, with iOS 8, if you
Set up autolayout constraints relative to cell.contentView
Use the estimatedRowHeight property
Dont implement -[UITableView tableView:heightForRowAtIndexPath:]
Dont use the rowHeight property
then you can take advantage of self-sizing cells that will expand automatically based on their content.
Check out WWDC '14 under "What's New in Table and Collection Views." You'll only need to watch the first 25 minutes or so.
Implement the following two TableView methods
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
Working with Self-Sizing Table View Cells Here is a useful reference.
I have NSTableView in Xib and connected outlet for that.I am loading the cell data using Key value bindings with NSArrayController.I need to fill the cell rows dynamically.I did it.But I am facing the problem,my Tableview cells are getting merged and lines of cell row are not visible.
Why is this happening,How to solve this.Can anybody have ideas please.
It is happening in 10.7.
It is probably due to cells heights in your table are higher that used in TableView by default. If this is your case:
Evaluate cell height in IB (row height in Size Inspector)
Add delegate method in proper view controller:
(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50.0; // for example!
}
I'm programming on objective-c. I have a viewController with tableView. I would like that my tableView has a dynamically height like on a picture below (Tweetbot). How can I make it?
Yes. However its not clear that this table is "short" - it may be that it has a transparent background and only two cells. In any case, to make a short table you would create a UIViewController class with a normal view (ie a UIView). Create a UIImageView and add the image to it (assuming you want a big image), and add that to the view (you could do this in IB). Then create a UITableView of the desired height, and add that too to the UIIView's subviews. Now you have a container view (self.view) with two subviews, the table being the last (so its on top).
Most likly tweetbot doesn't add a UITableView upon a UIViewController. They most likely use the UITableViewController from scratch, giving it a background and (in this case) showing only two cells with a custom height. That is also the "way-2-go" when using the Table View.
You should use -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath method and use if condition or switch case in this method.
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row ==2) {
return 89;//write your image view's height here.
}
return 44;
}
I am working with the UISplitViewController in iPad application.
Currently, I found two issues:
1. I can't modify the width of the master view
2. I try to use the customized cell in the master view, but it seems not possible to adjust the width and height of the cell.
Do you have any ideas on the two issues regarding to the standard UISplitViewController?
Thanks,
Mike
1) You cannot change the size of detail view.
Please check the following link, From that link you will get alot of information:
Change the width of Master in UISplitViewController
2) Use the heightForRowAtIndex delegate method. return 60 from that method
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 60.0;
}
I want to remove the selection color that appears when I touch a cell in my tableview.
In IB there is a "shows selection" checkbox that does nothing and it seems from what I can gather that it is just a bug in IB.
But then there is the
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
that I can set to each cell.
This also does nothing, so this is where I am stuck, all documentation say that if I set this property it should not appear but it does.
I push another UIViewController on a UINavigationController, and when I go back to the view in question, the blue background on the cell is stuck until I touch another one.
The only thing special is that I instantiate this UITableViewController with the help of storyboard and I use prototype cells. Then I put it inside a UIScrollView to have horizontal paging between multiple UITableViewControllers. There is no way to access the navigation controller when I do this so I pass the UINavigationController along to the UITableView.
Sorry that I can't make the keywords appear as code, it says I should press the tab key then type a $ but that moves my cursor to tags.
You might try to set the selectedBackgroundView of your cell like this :
customCell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"background.png"]];
In the delegate method cellForRowAtIndexPath
From code you can use (for example for grey):
cell.selectionStyle = UITableViewCellSelectionStyleGray;
And put this at:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
In your ViewController.
The solution was to set the style on the prototype cell in IB. Many things are wierd about prototype cells.