I make one UITableView Controller had static cell. And I set number of rows 3 in Storyboard. But rows does not set 3, just be made more and more like this screen shot. I don't touch any programatic code. Did I have to make it programmatically?
That's the normal behavior of a UITableView. Even though you only have 3 rows, the view itself extends to the bottom, and it shows where the cells would be if you had data in them. To fix, do one of two things: customize the UITableView so the dividing line between cells is invisible [UIColor clearColor], or change the size of the UITableView's height depending on how many cells you have.
If you add a footerView to the UITableView then it will not extend all the way to the bottom.
I solve this problem on the story board.
Create one more cell. if you want 3cells, then make 4cells.
Make whatever you want on cell. put the UIButton or UILabel any way. But except 4th cell.
Expend your 4th cell's height, to the bottom.
And finally, check hidden in attributes inspector. It makes 4th cell hidden.
That's it!
And I add one image file. I hope it help your work. Thanks.
Simple solution is to set footer's frame to nil:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
/*........*/
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
return cell;
}
I would use a regular View Controller and insert a TableView of the required table height.
Then if you really want to you can do stuff with the cell height and label sizes.
Related
I have a TableView with a custom cell. The cell is having multiple views and labels inside it. Now based on conditions I want to remove views and labels from the cell but in next cell I want them back and remove different set of views and label.
As I am using dequeueReusableCellWithIdentifier so after deleting the views from first cell I am not getting those views in second cell.
I don't want to hide them as I need some auto layout adjustment.
How can I do this?
Use prepareForReuse() in UITableViewCell:
override func prepareForReuse() {
super.prepareForReuse()
// add that view back
}
In custom cell you just add all view and label according to your requirement. In
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
}
you just hide or show view and label according to your need.
You can set a height constraint for the labels and views that you want to delete and set IBOutlets for the same, and instead of deleting the view from custom cell you could set the height constraint to 0 as per your condition. So the views and labels wont appear in the screen. Hope this will Help you. :)
I am using a Table View (not UITableViewController) with dynamic prototype cells.
However, when you drag a single cell into the tableView, a label with the word 'Prototype Cells' is displayed but then, this label (without the word 'Prototype Cells') appears when I run the app in the simulator.
Does anyone know why that is?
Thanks for your help in advance
The "Prototype Cells" label in the storyboard resembles a section header view, so you may be inadvertently generating an empty one. This could happen if you've implemented any of the related UITableViewDelegate methods. For example, the following would do it:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 20;
}
But without seeing a screenshot or your view controller's code, all we can do is guess.
I got the answer here.
self.tableView.contentInset = UIEdgeInsetsMake(-20, 0, -20, 0);
Thank you to everyone for your help.
I have a uitableviewcell with content view containing some custom view.'
When the table view enters edit mode the content view resizes (becomes narrower) there by the image in the content view is shrunk horizontally
Does anyone know how to prevent this ?
I have set the cell indentation to none.
Thanks
Have you tried setting shouldIndentWhileEditing to NO
Take a look at properties :
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html
Have you tried setting the auto-resize masks on the view?
theView.autoresizingMask = UIViewAutoresizingNone;
You may need to set it on the content view and/or the image view - it's not clear exactly how your view hierarchy is structured. However, the frame might be set explicitly (rather than auto-resized) by the framework, in which case this won't work.
If you are trying to have a background image for the entire table cell, you may also want to try an alternative method which is to set the backgroundColor of the cell like this:
UIImage* someImage = [UIImage imageNamed:#"someImage"];
cell.backgroundColor = [UIColor colorWithPatternImage:someImage];
Remember to make sure the backgroundColor of all other views you place inside are [UIColor clearColor] so that you can see through to the background image.
You can always get a tableviewcell with an indexpath. Using that tableviewcell reuseidentifier, You can avoid the tableview cell content size to be resized or not. I had a requirement to implement the similar kind of functionality to avoid resizing of seperate cells. PFB the code.
-(BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath{
BOOL shouldIndentWhileEditingRow = NO;
UITableViewCell *lTableViewCell = [tableView cellForRowAtIndexPath:indexPath];
/*Change the position of the target rect based on Sending messages or Receiving messages*/
if ([lTableViewCell.reuseIdentifier isEqualToString:#"SendingChatCellIdentifier"]) {
shouldIndentWhileEditingRow = NO;
}else if ([lTableViewCell.reuseIdentifier isEqualToString:#"ReceivingChatCellIdentifier"]){
shouldIndentWhileEditingRow = YES;
}
return shouldIndentWhileEditingRow;
}
I did something similar to avoid the cell content to be resized when using cell automatic dimension.
My problem was that the textView inside the cell, after the selection, was wrapping its content in more lines, and I just wanted to avoid this.
To solve this "issue":
I added a trailing constraint of 40px (the size of the accessory view) to the cell content
On cell select, i change the constraint to 0, so the text is 40 px larger, but as the accessory shows up, you don't see any changes.
The pro of this solution is that the content dimension is not changing anymore when user select a row.
the con is that you have always 40px of free space on the right of the cell, also when not selected.
i am using custom UitableViewcell (MainTablecell)to display the records. i am also providing edit and delete functionality.so that i want to shrink my custom table cell, can any one suggest me how to do this.my custom cell looking like bellow
cell.shouldIndentWhileEditing = YES;
and
-(BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
i tried with above poece of code but
Both are not working for me,How can i shrink all lables in my cell could you please help for me
When your tableView goes into edit mode, resize the labels.
shouldIndentWhileEditing: only makes the left side of the cell indent and does nothing for the content. You will need to manually resize the labels.
Depending on the design and code of that custom cell, you can call the label and perform setFrame: when in editing mode, just detect that mode and reload your tableView.
So, the correct number of rows shows up. On pressing any row, the correct action takes place. However, the cells themselves are nowhere to be seen.
I added a NSTimer in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
for each cell just to trace it out beyond the function - they all say that their superview is equal to the tableview in question (and is not nil, so i'm not checking nil == nil or something).
They all contain labels with the correct text.
The separator lines are being drawn.... If I change the TableView background, the whole visible area's background shows as that color.
I'm checking that each cell is neither hidden nor set to an alpha of 0.
Is there anything else I could be missing?
Are you loading from your cells from a nib file or creating programmatically?
Are you overlaying another object over your cell in the cell subview? Perhaps a subview is covering it; I can't tell, since you have not posted any code yet. Given the information you have provided, it is difficult to determine why you cannot see the cells backgroundView.
Try changing the color with
UIView *tmpView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
tmpView.backgroundColor = [UIColor blackColor];
myCell.backgroundView = tmpView;
It sounds like you have set the backgroundView of your cell to [UIColor clearColor].