I have a tableView where each cell triggers a modal view (it is a travel planner, the table is used to select origin and destination).
After selecting an address the modal is dismissed and the user is returned to the tableview. However, if I immediately select a cell the event is not recoginized, I need to wait a few seconds.
I've checked that neither shouldHighlightCellAtIndexPath or didSelectCellAtIndexPath is called.
After checking other questions here I also tried to set delaysContentTouches to false (for tableview and the embedded scrollview, see UIButton not showing highlight on tap in iOS7)
Do anyone know how I can make the tableview respond to selection immediately? The delay is just long enough to annoy the users
First of all on tap on UITableViewCell, delegate that gets called is didSelectRowAtIndexPath. This gets triggered instantaneously - always!
My guess is you are doing some networking on your main thread on tap on cell and then presenting new screen with that data. This would make UI look delayed and un-responsive. Please double check and ensure all non-UI stuff that need not require main thread goes in a parallel thread.
Related
I have a UITableView with at most a few hundred cells (not all visible at once). Each cell contains a UIButton with a way to indicate progress of an upload. A URLSession performs the uploads in background tasks.
Currently, the session delegate is the UIViewController that manages the cells. As a result, the session calls delegate
.URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend: to periodically inform the delegate of the progress of sending content to the server.
In the delegate method, I find the UIButton associated with this task and animate the new progress (I can find the button because I make button.identifier = task.identifier).
This approach forces me to find the button every time the delegate method is called. This seems indirect and I am wondering if there is a better way to do this — there could be 100s of buttons so worried about runtime.
I was thinking to make the button be the session delegate, but that goes against MVC and the button reference may disappear or change in a table view causing undefined behavior (though it sort of makes sense to only update buttons that are actually in memory).
there could be 100s of buttons
No, there couldn't. Cells that do not appear on the screen do not exist at all (because cells are reused in a table view). So you only need to worry about the cells that are actually visible at any one moment. See UITableView visibleCells and indexPathsForVisibleRows. Thus, even though your approach is not extremely efficient, it isn't extremely inefficient either.
However, the correct way to do this is to use the progress object vended by your upload task. When the upload starts, tell the cell or the button or whatever to start observing the progress object's fractionCompleted using key-value observing. Now the cell or the button or whatever is in direct contact with that one task and can update itself every time it hears that the fractionCompleted has changed. When the cell stops being displayed, stop observing. There's a little more to it (i.e. to cope with reused cells that scroll onto the screen when the corresponding task is already in progress) but that's the basic architecture you want.
I have a timer that insert a new item on a tableview every 2 seconds, it is required that the tableview shows this new line insertion with an animation of 1 second, the problem is that the user interaction is blocked while the tableview insert animation is happening, I tryied to pass as option for the animation the constant UIViewAnimationOptions.AllowUserInteraction, but it did not worked. What I need is that the user can interact with the tableview, selecting cells, scrolling etc even during the animation sequence. Any ideias ? The code for the problem example is on github
https://github.com/munhra/TableAnimationProblem
This video shows the not desired behavior
https://www.youtube.com/watch?v=Jb7dnCv5wXw&feature=youtu.be
I'm chasing this weird bug where my UITableView (which is backed by a NSFetchedResultsController) is being reloaded without me explicit asking for it. This UITableView has a UITableViewController as it's controller and a View Model as it's Data Source. The flow works as it follows:
Click the filter button
Filter screen appears
Select one filter
Click Filter button
tableView from presentingViewController is reloaded
Filter screen disappears
Now I know, some things can trigger the reload in this scenario:
A call to any of the reload functions (row/section)
NSFetchedResultsController delegate being called
None of these are true. The only thing that happens is the dismissal of the Filter List Screen - which is triggered by the Filter button:
#IBAction func filterButtonAction(sender: AnyObject) {
self.presentingViewController!.dismissViewControllerAnimated(false, completion: nil)
}
Note that the UITableView reloading is only happening after calling filterButtonAction, not before. This indicates that's something related to UIViewController's callbacks (viewWillAppear etc), but there's not a single reloadTable to be found (and I don't even implement viewWillAppear on the presentingViewController).
What could be triggering the tableView reload here? Is there a way to trace a call to the tableView data source?
Turns out this is an iOS 8 issue - I started testing in an iOS 7 device, and reloadTable wasn't called at random.
I have a UITableViewController that comes on to the screen in a popup. Basically it slides in from the left and shows the hierarchy available.
When it comes on screen, I select an item within it to represent the current location. Before today, this all worked.
Today I added a UITextView as a header to the table. Since then, my selection is acting strangely. When the UITableViewController appears, I can see my selected row get selected briefly, but it immediately becomes unselected. Calls to indexPathForSelectedRow return nil.
Is there a way to be alerted whenever the selection changes in UITableView? I know to use tableView:didSelectRowAtIndexPath: to keep track of when the user selects an item, but this problem is happening without user input. I'm assuming I've done something incorrect within the code, but I'm trying to track it down without posting all my code here.
Edit
Apropos of nothing, I did find that the problem goes away if I remove the Navigation Controller that I had added to the UITableViewController. This was because I had not set the property clearsSelectionOnViewWillAppear to NO. By adding the Navigation Controller, the UITableViewController was getting loaded differently, causing the property to actually be used.
However, I still would like to know how to be alerted to table view selection changes.
I have implemented a table view with multiple threads. Currently when a user taps on a cell a different thread starts downlading the content in the background and the user is free to choose a different cell before the content is loaded.
Currently the app will show the content of the first tapped cell and then immediately switch to the content of the 2nd cell.
My question is if a user selects a cell and then before the app can switch to the detailview they select another cell, how do I only show the contents of the second cell and forget about the 1st cell?
You have different ways to do this; speaking generally you'd have a callback of your asyncronous computation. In that callback, simply look at the last indexPath selected and match whether or not it's the same indexPath who triggered that computation.