App crashes if the view disappears while the UiTableView is being reloaded - ios

I have a view with the list of entities pulled from a remote source (via web-service). App crashes, if back button is pressed (view with tableview disappears) while the entities are being loaded on to the table view.

If any keyboard appeared, resign the keyboard.

What about using NSOperation to retrieve the data from your Web Service, and cancel it if the user press the back button?
http://nshipster.com/nsoperation/
Another Option would be to check the view in the completion handler (when your data is ready)

you have to stop the remote service call in viewWillDisappear (or) use IgnoringInteractionEvents up to that page load.

Related

WKInterfaceController cancel button

Is there any way to know when the cancel/dismiss button is tapped on the Apple Watch?
- (void)didDeactivate
Is not an option because that is called whenever the watch goes dark. I'm trying to sync data with the parent iPhone app and this makes it tough to cancel an operation on the parent app.
While you can't get the cancel directly, you can tell which view controller is active (because your code displayed it) and then tell when they switch. So you can set some flags on display and on de-activate, to tell when the view controller with the cancel button goes away.
Think of it another way, if your view controller disappears and another one displays, the activate of the other controller tells you the watch did not sleep.
Unfortunately, the current version of WatchKit has no method to determine if the Cancel button is tapped. The closest you'll get is the didDeactivate event that you've already mentioned.

how to reload tableview upon return to tableviewcontroller

In my app, there are tabs. I have one tableviewcontroller that contains messages and I have implemented pull to refresh so that works fine. However, if the user goes from the message tab to another tab and then back to the message tab, the uitableview doesn't reload and the user has to pull to refresh. I have thought of putting [self.tableview reloadData] or [self loadObjects] (i am using Parse) in viewDidLoad/viewWilAppear, but that doesn't seem to work...it's because they are only called when the view controller is initially visited right? So I'm wondering as to where I should put that code so that the table view can be reloaded every time the view controller is revisited?
viewWillAppear and viewDidAppear are both called every time the view controller appears. If you call reloadData in one of those methods then it will refresh the table view.
I think your problem is you aren't updating your data source. You will need to make another call to Parse otherwise your table view will just reload with the same data.
I don't think that this behavior is desirable. I suggest you tu wait for a reasonable timeout before updating data, or your user will experience lags and high network usage.
However to do that, you should set a delegate that fires when the corresponding view is loaded (take a look here how to get the event that switch tab menu on iphone ) and then call
[yourTableView reloadData]
inside didSelectViewController

UINavigationBar not updating bar button item until after table view update

I have a UITableViewController embedded in a navigation controller. My rightBarButtonItem is a refresh button. When pressed, the button triggers an update from a server. The update is synchronous (when I have time, I'll change it to an asynchronous request). What I want to do sounds simple in theory. Once the button is pressed:
Change the bar button item to a UIActivityIndicatorView
Refresh the data
Reload the tableView
Change the bar button item back to a refresh button.
What's happening, however, is that I will set the rightBarButton to a view with an activity indicator view, but it's not getting updated until after the table view reloads, which is obviously pointless. My server update routine looks like this:
View Controller calls a separate model object's "refresh" method.
model object synchronously gets the new data from the server
View controller calls [self.tableView reloadData];
Since it's synchronous, I thought it would simply progress one step at a time, but that's not working. How can I make it so that the activityIndicatorView shows and disappears when it's supposed to?
When you modify the navigation bar, the modifications aren't actually applied to the screen immediately, they are applied during the next screen update cycle, or next screen refresh, or next redraw.
In your code, it seems like you send a synchronous request to the server immediately after setting up your navigation bar. That request now blocks the main thread, and the system cannot refresh the screen, as all UI code runs on the main thread.
Using an asynchronous request, or simply sending the request on another thread, or some other witchcraft you'd like to try with a synchronous request will help you solve your problem. But the essence of these solutions would be the main thread will not be blocked by any synchronous methods.

How to organize properly the transition back in UITableView

In my app I load data from URL, parsing it, and put in TableView. When user push on some row - initializing method in which pass element's ID and again load data from URL, parsing and reloading TableView. This continues until user saw last element, when he push on it - opens new ViewController (DetailViewController for example). It will be good if user can go back and see in reverse it all. With DetailView all clear - just organized data back with segue, and reload scene.
But the my question is - How to make that when user push Back button on Tableview, TableView reloading in right reverse order?
In this case navigationControl is your friend. Build different views for any click, then instantiate and call the pushViewController with navigationControl. The navigationControl will handle the back button it self.

Tableview refresh/reload like in Reminders app in iOS5

I built an app that displays a tableview. If the user tap an entry it goes to the detailed screen. In the detail screen, I have a button to delete this entry. I delete the record from the datasource and go back to the previous screen (the one with table view). I can create a refresh button and call the reloadData method, which is working fine. However, I would like to eliminate refresh button and it refresh the data automatically. Like in the new app in iOS 5 called reminders. I can tap the task and it goes to the details screen. If I delete the task in the details screen, it will go back to the previous screen and the records has been removed from the display automatically.
Any idea on how to accomplish this?
Thanks.
whenever you enter the tableview from detailview override viewwillappear delegate
-(void)ViewWillAppear
{
[tableview reloadData];
}

Resources