I have a uiview inside the tableviewcell. When i run the code with ios 8 the table cell look good and working fine. But when i try to run this code in ios 7 the table cell contents overlapping on the other content of the cell.
Can anyone help me to do that correctly.
Attached the Tableviewcell scrrenshot as follows:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(!self.customCell){
self.customCell = [self.goalDetailsTableview dequeueReusableCellWithIdentifier:#"GoalDetailsCell"];
}
//Height of cell
float height = 360;
return height;
}
Thanks in advance.
I have solved this issue by myself.
When you are running in ios7, just set maskToBounds = YES in tableViewCell implementation file.
- (void)layoutSubviews
{
self.cardDetails.layer.masksToBounds = YES;
}
Related
I met this issue after I upgraded xcode to 6.3. The former build compiled using xcode 6.2 doesn't have this issue and works great.
The issue is: After switch to other tab and back, or back from push segue, the width of most cells will shrink a little bit. But some don't. And it looks like following
The label content in 2nd line of cell has the correct width. And all cells display content with the correct width after first launch.
In above image, there are two uitableviewcells.
content view : blue;
background view: light green;
content Label: purple;
The bg view and contentLabel in 1st cell shrinked. That's what I don't want.
I use storyboard to set the constraints.
bg view's constraints.
labelview's constraints
I also tried to cache the cell height as per this question UITableView layout messing up on push segue and return. (iOS 8, Xcode beta 5, Swift), but it doesn't work.
//In viewDidLoad
self.tableView.estimatedRowHeight = 100.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.contentInset = UIEdgeInsetsZero;
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
float height = [[self.estimatedRowHeightCache objectForKey:[NSString stringWithFormat:#"%ld", indexPath.row]] floatValue];
if (height) {
return height;
} else {
return UITableViewAutomaticDimension;
}
}
//cache row height. I observed this doesn't been called in first launching in debugging.
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[self.estimatedRowHeightCache setValue:[NSNumber numberWithFloat:cell.frame.size.height] forKey:[NSString stringWithFormat:#"%ld", indexPath.row]];
}
Thanks for your help!
Well you are not setting the Horizontal Space Constraint for the view on top of your contentView. You are only setting Horizontal Space Constraint for your label and its superview.
Do this
Select the view which contains the label
Editor > Pin > Leading Space to SuperView
Implement DataSource Method for Tableview WillDisplayCell
Or you can implement in cell class (if it's custom cell) method - (void)awakeFromNib and there set cell frame.
I have used the following code to dynamically change the row height in ios. But the height is too high. I dont know where i made mistake. My code is as follows:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(!self.customCell){
self.customCell = [self.goalDetailsTableview dequeueReusableCellWithIdentifier:#"GoalDetailsCell"];
}
NSMutableDictionary *cellData = [self.databaseCall transactionFromDatabase:indexPath.row goalId:self.goalId andStageId:self.stageId];
//Cell Layout
self.customCell.tipsDescription.text = [cellData objectForKey:#"tipsDescription"];
[self.customCell.tipsDescription sizeToFit];
//Height of cell
float height = (CGRectGetMaxY(self.customCell.tipsDescription.frame) + 20);
return height;
}
Note: tipsDescription is a UILabel inside the UIView which is kept inside the UITableViewCell.
You need to calculate your text height and based on it have to set cell height (yes, its going to be little mind expensive but at last you'll be happy!). Here's the one solution for this, Replacement for deprecated sizeWithFont: in iOS 7? and if you want some more info, Calculating number of lines of dynamic UILabel (iOS7) and this too UITableViewCell with UITextView height in iOS 7? (I know its not for UITextView but you can consider it with UILabel).
With iOS 8 we have self sizing table view cells. With it, there is no need to even implement heightForAtIndexPath.
Step 1) Set up constraints for your table cell
Step 2) In viewDidLoad:
self.tableView.estimatedRowHeight = 100.0; //or whatever value you need
self.tableView.rowHeight = UITableViewAutomaticDimension;
And that's it. I would also mention a few of us have ran into an issue where you might need to reload the table view's data in viewDidAppear.
These two pictures should explain it. The first shows my UITableView normally. The second shows when I touch the UISearchBar and it takes focus. Why is there a gap between the cell header and the search bar? Anyone know how to fix this?
iOS 7 is when this occurs by the way. I already have this code:
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView)
{
return 0;
}
else
{
return 23;
}
}
I fixed this problem in my code by removing the following 2 lines of code.
self.viewController.edgesForExtendedLayout = UIRectEdgeNone;
self.navigationBar.translucent = NO;
Hope that leads you in the right direction.
In iOS 7 there is small area on the top of UITableView. This is the header of UITableView.
Add following code to your controller ( UITableViewDelegate class ).
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 1;
}
I have an issue on iOS 7 with a custom cell drawing (on iOS 6 and 5 is working fine).
On heightForRowAtIndexPath I'm returning a smaller height than the real height of the cell for the last row of each section, because I need the last cell to overlap with the header of the next section.
It seems that Apple made a drawing improvement or something on iOS 7 because only the height returning from heightForRowAtIndexPath is drawing so my cell will be cut at the bottom.
Any ideas will be appreciated.
Hmm here is what I would do...
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == [_array_todo count]) {
// last row
return 50;
}else{
// not the last row
return 80;
}
}
Also consider what you are doing when cell is selected....
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
sel_path = indexPath;
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
I had the same issue and situation(tapping last cell with lower height to add more data). I didn't research why that happens, but something worked for me. I used data for table from NSDictionary. It worked perfectly for iOS6.1 and earlier. In iOS7 it led to same bug as yours. Allocating data into separate NSMutableArray in viewDidLoad solved it. So instead of using everywhere in tableview delegate methods
[self.data objectForKey:#"offers"]
I did
- (void)viewDidLoad {
[super viewDidLoad];
if (!tableData) tableData = [[NSMutableArray alloc] initWithArray:[self.data objectForKey:#"offers"]];
}
And replaced all. Hope that helps for you too.
- (void)reloadUI
{
[_createNoteView layoutSubviews];
if (_list.is_archived == 0) {
_tableview.tableHeaderView = _createNoteView;
}
[_tableview reloadData];
}
I have a resizable input view called _createNoteView,[_createNoteView layoutSubviews] will correct its own frame.
each time content of _createNoteView was changed reloadUI will called.
I expect _createNoteView will will resize while I'm typing in it. But things won't work in iOS 7;
Everything works well on iOS 6 with the same context;
As your question is not very much clear, this is a general answer.
Have you used this tableview delegate method
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 60;
}
You can calculate the size of header in this method and return the specific height
The previous one is for tableview section's header.
May be this could also help
tableView.tableHeaderView = nil;
tableView.tableHeaderView = your_headerView;