I have a UIWebview with a 'Back' button.
Whenever it is pressed the previous page completely loads again, making navigation sluggish. As part of the reloading it also scrolls to the top again so you have to scroll back down to where you were.
How do I prevent the page from reloading and just show what was previously there?
If someone clicks an actual link to go to a previously visited webpage then it should, of course, load that page again.
I don't think UIWebView reloads the page by default, however, depending on how you are presenting it, it may want to reload on, say, layout changes. If this is the case, you can try doing something like:
if webView.loading {
webView.stopLoading()
}
...every time you update the layout and do not expect it to reload its contents. Updating layout may happen, say, when you present the view controller with a UIWebView to the user; or when orientation changes, updating UIWebView's bounds. Alternatively, if you are anywhere near UIWebView's delegate, return false in shouldStartLoadWithRequest callback instead of calling stopLoading().
Related
I am using uiwebview to show my web contents. Navigating to different url using RevealViewController. I am caching all the pages for the first time entry.
After visiting few pages when trying to goto rear view (reveal view controller menu screen), the app got stuck for some time on clicking of the menu button.
(Every time visiting and caching a page that will increase the memory size of the app)
If the presentation of the menu is slow, it is probably because you are doing some heavy processsing inside the initialiser of the menu or the viewDidLoad function, or the menu button pressed function.
My suggestion is to move any of that processing to the viewDidAppear method of your menu controller instead, so that the UI is not blocked by any processing you do. You could also use GCD to disaptch_async anything that is intensive.
If you give some code examples it will be easier to see exactly what the problem is, particularly the code that executes when the menu button is pressed.
iOS 7 introduces edge swiping to navigate backwards in a navigation controller (so long as you don't override the leftBarButtonItem, among other things).
Imagine I'm implementing an app similar to Apple Notes. In Apple's app, once the user taps into a note, there is a Back button on the top left, and a Done button on the top right. This view controller is automatically saved after the user navigates away. Even if the user swipes backwards while still editing the note, it will auto-save.
One way to implement this is to write to disk on each key stroke. However, I'm looking for a more efficient implementation.
Which method should I override to perform my auto-save?
To be clear, the auto-save code should be invoked in these three cases:
The user taps the Back button
The user swipes backwards
The user taps the Done button
So far, I've been implementing the save logic in viewWillDisappear, this minimizes the amounts of writes, and also takes care to save if the user kills the app.
Additionally, instead of implementing save logic in the Done button, the Done button can simply call:
[self.navigationController popViewControllerAnimated:YES];
... (e.g. via a delegate, or unwind segue) and it will automatically save as well. All three code paths will go through viewWillDisappear.
Although it could technically be implemented in viewDidDisappear, if the previous view controller needs to display the updated data, this method will be too late.
For more complex view controllers (e.g. those that have destructive behavior once the view controller is dismissed), there are several other things to consider:
Should the save be called if a modal is presented above the current view controller? (e.g. In Apple Notes, imagine that the share button launched a modal; should it save when you tap on this button?). If it is important not to save at this time, you can read the value of presentedViewController. If it has a value, that means viewWillDisappear is being called because a modal is being presented above it.
Should the save be called if a view controller is pushed on to the current navigation stack? (e.g. Again, in Apple Notes, if the share button used a push instead of a modal, should it save?) You can check the value of isMovingFromParentViewController in this case.
If the user taps the home button to quit your app, should it save?
If the user begins swiping backwards then cancels the swipe to stay on the current screen, should it save?
Imagine the view controller is in a modal, when the modal is dismissed should the destructive action happen? Check isBeingDismissed in this case.
Same as above, but imagine the view controller is the second page in a navigation controller than is being presented.
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
I'm working on a problem where I have a ViewController which opens a popOver when a button is pressed and then in the popOver you can edit some settings which affect the content shown in the mother ViewController (for instance change the color of the View, change a map or a table there). This can be off course called whenever the popOver is dismissed, but it needs to be live up-to-date.
I tried using delegates, where I can pass over data or call a function but the function won't be started on a ViewController wchich isn't active, right?
I also tried NSNotifications but it didn't work either.
I found several questions like this on stackoverflow, but there is no real answer yet:
UIPopoverController button selecting method of another ViewController but not updating its view iOS
Refresh the view controller from popover
Refreshing a view from a popover
Refresh a WebView in a ViewController from another ViewController
how to refresh or reload a uiviewcontroller
Can somebody please explain a generall way with some code snippets how to get this fixed?
Delegation is a fine solution. The target view controller is presumably still visible underneath the popover (which shouldn't fill the screen). In this case when the target receives the delegate callback it can do any updates and refresh its views to update the UI without any limitation. In this situation both view controllers (the 'target' and the popover) would both be classed as 'active' as they are both visible on screen.
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];
}