Why is there a floating "2" in my UITableView? - ios

In the image below you can see a 2 appearing to the right of my UITableViewCell's accessory buttons. This only appears when I am using section headers (which is what I'm currently adding to my existing UITableView. If I fetch the data with sectionNameKeyPath:nil then the 2 doesn't appear.
My guess is that this 2 is appearing instead of the scrollIndicator. The 2 always remains in the center of the UITableView. When I don't use sections I see the scrollIndicator as expected. Does anyone know how to fix this?
Edit:
This shows that the floating 2 is a part of the scroll indicator.

hahah, that's great :) Butt! i think a way to find out where it's coming from is using the Debug View Hierarchy. Run your app and once you see the two in your table view:
once xcode has loaded the view from the Simulator, look for the two and click on it. at the top you'll see where this object is located.
Then i would try to back track on how it was added to this view. maybe it's part of a cell? etc.
I hope this helped getting closer to the answer :)

Well I finally found the problem. My superclass had the following code:
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return [self.fetchedResultsController sectionIndexTitles];
}
I must have picked up that code from an example somewhere when I setup my superclass for UITableViewController. In this case I don't want index titles, just the scroll indicator, so I removed that method.

Related

iOS infinite scroll items disapearing (sometimes)

This is a very rare occurring bug from hell,
I have an infinite scroll controller that displays products, 2 in each row. Rarely, something affects the controller and causes items to vanish, when I tap the empty area where the item should be, it works as expected and directs the user to the item details controller. When I back out back to the list, sometimes the cell shows its content, and others get hidden.
Sometimes it just a couple of items missing, sometimes there are so many missing items that makes the list appear empty, like only 1 or 2 cells are visible per screen height.
An even stranger situation is, when I scroll really fast to the end and stretch the screen really fast out of the visible area, and there are no more items to load, the visible items can jump from left to right.
Please see these two videos.
https://www.dropbox.com/s/jibflcouz1ena8n/missingProductImages.mov?dl=0
https://www.dropbox.com/s/uz13fzorypnp38t/again.mov?dl=0
I could send code but I didn't want to clutter this place with full length code, let me know if you want to see a specific section of the code please. Maybe someone could have an idea of what might be going on by looking at the vids.
What's probably going on here is a state problem with your collection view cells. The code assigning model values to the cell's views would be of use here. But absent any actual information, the first thing to review would be the cell's prepareForReuse implementation:
Does it call super?
Does it clear out all current values?
Does it cancel any pending asynchronous operations?
Are fetches and cancellations correctly matched?
Next, check if there's any essential configuration in the cell's init/initWithCoder methods -- those are only called on first creation, not on reuse.
Those are the normal pitfalls of UICollectionView cell handling. If they don't suggest the problem, please post the cell code.
It looks like your cells are not being reused correctly.
Can you check that you have set the same reuseIdentifier for your cell in Interface Builder that you are assigning in your code?
Update: Attached image to show where to set the identifier in the storyboard/xib
Update: added layout solution
Another problem could be due to the layout bounds of your collectionViewCell. When you load your cells they bounds are not calculated until they have been added to your collectionView and rendered. This can cause the elements in your cell to layout with the wrong values. This happens commonly with async image frameworks as they cache a resized version of the image for performance. When you cell loads, the cached image is loaded at the wrong the wrong size.
Add the following code to your collectionViewCell:
- (void)setBounds:(CGRect)bounds {
[super setBounds:bounds];
self.contentView.frame = bounds;
[self setHighlighted:NO];
}

Remove blank space under UITableView

I have regular UITableView with UISearchDisplayController in Navigation Controller. SizeToFit works on viewDidLoad normally, without any problems. But when i enter search a write some letters, it returns me items, that OK but size of tableview fails.
It is scrolling well, from the bottom to the top but when i reach last item, it stops in middle (it looks like 1 or 2 cells are missing but they are not) & HorizontalScrollIndicator also reach just the middle of tableview.
Any advice ?
It's possible that after you've provided some search parameters and manipulated your data source, you are missing a call for
[self.tableView reloadData];
Hard to tell without the code, but the tableView may be attempting to display rows that should not exist anymore - causing an error in cellForRowAtIndexPath

Self Sizing Cells make UITableView jump

I've got a UITableView, each cell has an image and two labels, as you can see on the first picture
So I am trying ti use self-sizing cells and everything is great, except 2 things:
1) First and Second cell don't show content properly, but after I scroll down and then return to them everything is ok. I tried to use [tableview reloadData] in viewDidAppear, but it doesn't help. Watch the labels at first they don't fit. You can watch it on this video https://www.youtube.com/watch?v=I9DGBl1c5vg
Look at the labels on the first cell.
2) It's a tough one. I'm scrolling the table and everything is great, but the problem happens, when I select the row. It's pushing me to detail view, but when I press "back" and return to master view, the tableview jumps,so I'm coming back not to the selected row, also if I scroll the table it doesn't scroll smooth, but jumps. Here are the links for two videos, first one shows that scroll is smooth https://www.youtube.com/watch?v=9wAICcZwfO4 if i don't go to detail view, and the second shows the jumping problem https://www.youtube.com/watch?v=fRcQ3Za1wDM .
It's absolutely sure connected with self sizing cells, because if I don't use it, none of this problem happens.
Okay, I solved both of the problems.
Question 1
I've added these two lines
[cell.contentView setNeedsLayout];
[cell.contentView layoutIfNeeded];
in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath before return cell
Question 2
The solution appeared to be very simple. I've just needed to implement viewWillDissapear and reload data in it, so the code looks like this
- (void)viewWillDisappear:(BOOL)animated;{
[super viewWillDisappear:animated];
[self.tableView reloadData];
}
Solution for me was simple, if it doesn't work for someone, here I found some useful links.
1) UITableView layout messing up on push segue and return. (iOS 8, Xcode beta 5, Swift)
2) http://useyourloaf.com/blog/2014/08/07/self-sizing-table-view-cells.html
Unfortunately I believe both of the questions that you ask about are IOS bugs.
Question (1)
A easy fix is suggested by this blog.
When the table view is first displayed, you may find some of the cells are not sized properly. But when you scroll the table view, the new cells are displayed with correct row height. To workaround this issue, you can force a reload after the view appears:
Simply add the following to your viewDidAppear method. I have tested it and it works very well.
[self.tableView reloadData];
Question (2)
This second question is a duplicate of this following question:
IOS 8 UITableView self-sizing cells jump/shift visually when a new view controller is pushed
A workaround is suggested by the author of the question himself, which seems okay. However, I have not tried out this one yet.
Okay, I solved it by caching my cell heights in sizeThatFits, and returning that value for estimated cell heights within the delegate. Works beautifully.
Feel free to head over to that question for other proposed solutions.

UICollectionview and/or UITableview cells not selectable until after view scrolled?

For every collectionview and tableview within my app, none of them are recognising the selection of a cell unit AFTER the table or collection has been scrolled a little?
This only happens within this current app, no different methods have been used, no collection/table subclassing etc. All collection views and table views are implemented with all relevant dataSource and Delegates hooked up and implemented etc.
As this is a common thing will all my tables, I'm wondering if it is a setting within the project that is causing this.
If anyone has experienced and previously solved this issue, I'd appreciate any help.
Salient points that may be relevant -
-All collecitonviews / tableviews are set up on storyboard.
-All cells are added directly to table/collection within storyboard and cell view configured using their own class files.
-Deployment target 7.0 for iPhone only
-All tables/collection cells are loading fine, everything looks fine with no crashes... just that the tables need 'woken up' so to speak?
Thanks in advance,
Jim
I've had similar issue, and I fixed it by subclassing UICollectionViewCell/UITableViewCell and setting selected property to NO in prepareForReuse method.
- (void)prepareForReuse
{
self.selected = NO;
}

Table View: replace whole data on click

I've been searching for a really long time but I found no answer for my question(s).
In my app I have a segmented control with two buttons.
When I toggle between those buttons I do:
Show a loading screen as a subview
do an url request to get the content to show in my tableview
fill my dataArray for my TableView with the new data
call reload data
remove loading screen subview.
In most cases everything works fine, BUT..
Sometimes, really not often, the table view "crashes", after this 5 steps. It means. The view only show one or two cells. And when I scroll to top or bottom I only scroll into white. In my current solution I can't reproduce this error on my iPhone(IOS6), only in simulator(IOS7). I think it has something to do with scrolling while changing the data of the table view. It only occurs while scrolling and pressing the segmented control button shortly after started scrolling, but only sometimes. But it could have another reason for sure..
My Question is, what could cause the table view to layout wrong (only displaying some cells correctly and scrolling into white), any Idea? And how can I recover/redraw the whole tableview after this happened? Please help..
I read a lot about [tableview beginUpdates],[tableview endUpdates] and insertRows, but I think this is not the right solution in this case. Or tell me if I'm wrong.
Here is the main code snipped for steps 2-4. If another part of code could help, maybe the cellForRowIndexPath, let me know.
NSMutableArray *newResults = [[NSMutableArray alloc] initWithArray:[self getResultsForRequest:url]];
[resultsLock lock];
results = newResults; //results is the data source for my tableView
[resultsLock unlock];
[self.tableView reloadData];
Thanks to all responders.

Resources