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.
Related
Hi i have been searching around to find a way to remove a static cell with animation but i have not found a solution to the problem.
I have also tried: [tableView deleteRowsAtIndexPaths:[self.taskArray objectAtIndex:indexPath.row] withRowAnimation:UITableViewRowAnimationFade];
but no success.
You need to hide cell before it is shown, in UITableViewDelegate's tableView:willDisplayCell:forRowAtIndexPath: method. This is the last method in your control where you can manipulate the cell display. It does not remove the space the cell takes, so another thing you can try is to set cell row's height to 0 using the tableView:heightForRowAtIndexPath: method of the same protocol.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
if (yourCell) {
return 0;
} else {
return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}
}
As your tableview is static, you cannot use deleteRowsAtIndexPath. The best option would probably be to migrate your data into a dataSource method for the tableview.
If this is impossible, then this answer ("UITableView set to static cells. Is it possible to hide some of the cells programmatically?") gives that the best method is to use the third party library
StaticDataTableViewController 2.0 (https://github.com/xelvenone/StaticDataTableViewController).
Otherwise you have to use the somewhat hacky method of changing the row height to 0.
I am using cells with two heights based on some status.
When start is StatusAwarded it shows full cell else it will show a part of it.
Here is the code to achieve this.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
SomeClass *someClass = dataArray[indexPath.row];
if (someClass.status == StatusAwarded) {
return 252.0f;
}
return 110.0f;
}
It works all fine but when it is in edit mode, it has this issue as shown below.
I am having effect like this while editing (Deleting).
Question:
Why is this happening? How to fix this?
Note: Clip Subviews is set to YES
Try to enable Clip Subviews in Interface Builder / Storyboard.
You're not reloading the other cells, try:
[tableViewAdvancedBookings reloadRowsAtIndexPaths:[indexPathsToExpand allObjects] withRowAnimation:UITableViewRowAnimationAutomatic];
instead of:
[tableViewAdvancedBookings reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
which only reload the currect selected cell..
or maybe try reloading the whole table like:
[tableView reloadData];
and see what happen.. hope i've help, for some reason.. Good night, Cheers..
I have a tableview that auto scrolls only in iOS 8 when I open a new view using [self.navigationController pushViewController:newViewController animated:YES];
Detailed Problem :
Now I'm going to give a detail of how I'm getting the problem, it's particularly in iOS 8. Take any tableview having around 50 entries, scroll it down to make the 10th entry at the top of the tableview. Then select any item on the tableview. Use the below method to push a view controller on row selection in tableview.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
// Open the New View
NewViewController *newVC = [[NewViewController alloc] init];
[self.navigationController pushViewController:newVC animated:YES];
}
Now you will find that on coming back from NewViewController to the previous ViewController, the tableview autoscrolls some distance. The tableview doesn't stay at the place of scroll it always changes its position automatically.
I had the same problem. I was using the new iOS 8 feature dynamic cell heigh. I was setting:
self.tableView.estimatedRowHeight = 50.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
The problem was that some cells were much higher than 50. Solution was to provide delegate method estimatedHeightForRowAtIndexPath and return values that are closer to the actual cell height. For example:
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 1) {
return 300.0;
}
return 50;
}
Another solution is to calculate cell heigh using systemLayoutSizeFittingSize inside cellForRowAtIndexPath and cache that value. Inside estimatedHeightForRowAtIndexPath supply cached values but return default if the cell height wasn't cached yet.
Just remove self.tableView.estimatedRowHeight = xxx; It works for me . The problem happens in iOS8 and does not appear in iOS10
I'm trying to display an array of strings in a table format. Following method gets called only 11 times, (the screen gets filled with 11 rows):
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyTableCell = #"MyTableCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyTableCell];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyTableCell];
}
cell.textLabel.text = self.MyArray[indexPath.row];
return cell;
}
My array has 20 strings but only 11 are getting displayed on the screen(I'm running this on simulator). There is no scroll bar coming up for the table. The screen is stuck with just 11 rows. in my XIB i just have this tableview alone, nothing else. Can somebody help me, thanks in advance !!!!
Could you show the - tableView:numberOfRowsInSection: method. Is it returning
[self.MyArray count];
Also bare in mind that using mouse's scroll wheel doesn't work in the simulator. You have to click and drag to simulate scroll.
This question already has answers here:
UITableViewCell frame height not matching tableView:heightForRowAtIndexPath:
(3 answers)
Closed 9 years ago.
in table i am setting the height for cell using(heightForRowAtIndexPath)delegate of table view
the code is:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 100;
}
but i am checking the size of cell in delegate method(cellForRowAtIndexPath) and code is:
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Dequeue or create a cell
UITableViewCellStyle style = UITableViewCellStyleDefault;
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:#"BaseCell"];
if (!cell)
cell = [[UITableViewCell alloc] initWithStyle:style reuseIdentifier:#"BaseCell"] ;
cell.textLabel.text = [NSString stringWithFormat:#"Cell %d", numberOfItems - indexPath.row];
NSLog(#"%f",cell.frame.size.height);
return cell;
}
when i am printing the value(frame of cell)cell on console its giving me 44.00.why this is happening even i am setting height of cell..please explain me and what to do to get the cell oh height 100..thanks in advance
actually i want to make custom type table view which support difrrent orientation of view and it is universal app so it will better to call the cell size in behalf of checking every time (iphone/ipad,diff orintation)....plz help me to accomplish requirement
If the cell is being shown correctly, and by correctly I mean with a height of 100 pixels as you have written in your tableView:heightForRowAtIndexPath:, I'm pretty sure it's because you're asking for the cell's height in the wrong place:
the cell has just been init'd with the default init method, the height returned is therefore the default one, of 44 pixels as nslog prompts in your console, on rendering the delegate sets the right height returned from your method and everything is set up correctly.
I had this issue months ago, for some reasons I needed to know cell's height in the tableView:cellForRowAtIndexPath: method, I came out with a workaround for that: I've stored all rowHeights values in an NSArray, since they were dynamic and different row by row according to their content.
I came out with something like
CGFloat height = [[heightsData objectAtIndex: indexPath.section] objectAtIndex: indexPath.row];
Do you have set your delegate for UITableViewDelegate ?
Try to put any log in your tableView:heightForRowAtIndexPath: method at first to see if your delegate is set.
hi friends dev had given explanation
NSLog(#"%f",[self tableView:tableView heightForRowAtIndexPath:indexPath]);