i found like my question answers, but my app stil not working.
I push view to controller-2 from controller-1. In controller-2 Restkit loading data, but not loaded, i quickly press back button to controller-1 and after few seconds app is crushing (Restkit loaded data).
I using ARC.
Please help me fix this problem. Thank you.
This happens because RestKit continues the network activity and then cannot find your controller since it has been closed and its location in memory deallocated. I'd suggest either adding some logic to prevent the user from hitting back while RestKit is loading data, or canceling all pending network requests like mja suggested.
One way to do this is to add the following line to viewDidUnload:
[[[[RKObjectManager sharedManager] client] requestQueue] cancelRequestsWithDelegate:self];
Related
I'm creating a SwiftUI multiplatform app in XCode and I have a section of my code that hangs. I want to update the user so they know what's happening and are willing to wait. I originally planned to have an alert with text that changed and then planned to have a Text element that updated. In both cases this isn't shown until after the code executes and as such only shows the final message (normally the success done message unless an error made it end sooner).
Is there anyway I can have a visible message to the user through an alert or SwiftUI element that is updated right away and thus will be helpful?
The fact that the alert isn't even shown until after the code executes is bad and incorrect. This suggests that you are doing something lengthy on the main thread, and that is an absolute no-no. You are freezing the interface and you risk the WatchDog process crashing your app before the user's very eyes. If something takes time, do it in the background.
I know that there are delegate methods.
In my case, the scenario is little bit different. When I load my request, there are subsequent calls that happens. So the page get loaded back to back with 3 urls. After that, it stops.
When it is done loading everything, after that actually I wanted to do something like 'autosubmit', which is not possible for mobile browsers. I am looking for a work around. But for that too, I need to make sure that the webView has done loading.
So my question here is, is there any proper way to find out that the web view has finally stopped loading, and then I can try something to do my 'autosubmit' part?
I have an answer to the detecting when the web view is done loading part of your question... Unfortunately, the most reliable method I have found is to increment a counter whenever webViewDidBeginLoad: is called and decrementing it whenever webViewDidFinishLoading: and webViewDidFailWithError: is called. Whenever the counter is equal to 0 you know that the web view is not loading.
Placing this check in the webViewDidFinishLoading: and webViewDidFailWithError: methods will allow you to determine when the web has completed or stopped loading (in the case of a failure).
I made my project in storyboard in, due to issue with the custom UITableViewCell I have made a new project, copied all of the data to my new classes and copied my buttons, images etc from the storyboard views to new project's nib/xib files.
Now When I click on any button my app crashes without any error and it opens delegate file and highlights this line of code
return UIApplicationMain(argc, argv, nil, NSStringFromClass([ThisOrThatAppDelegate class]));
I have already made connections for the required actions from IB to controller. Also I have tried Command+Shift+K for clean code. But the problem is still there.
You have to find out first what the problem is:
use the Debug build config and are using lldb or gdb
make sure you have a breakpoint on all exceptions
make sure you have the "Breakpoints" button top left enabled.
run the app
You should break into the debugger. You need to get to a point where the debugger catches the exception.
Then edit your question and tell us what exception you get. I'm going to guess you'll be getting a objc_msgSend() error, which means that some object is trying to message a non-existent or dealloced object. If that turns out to be true, then you can enable "Zombies" (which lets all objects stay around) and see if one of those gets messaged.
If nothing seems to help, then what you need to do is start adding NSLog messages to track your app as it comes up (or use breakpoints, your choice). This takes a long time so you might work backwards - see if your appDelegate application:didFinishLaunchingWithOptions: gets called, and also if you get to the end of it.
Unforunately this type of problem can be take a lot of time to track down. Some object has probably queued a message up for another object on the main queue, so when you get the crash you don't get to see who did what when.
Also, with objc_msgSend problems, when the debugger stops you cannot easily see what object was messaged - but if you turn off the debugger and let the app actually crash, you can find the crash report in the Console app and get more info from that.
I finished building a small app with audio, clicking "next" button will play a sound and take me to the next page, clicking "back" will play a sound and take me back to the previous page. But if I do the next, back twice, the simulator crashes and I receive the below message from the log. Anyone can help please, cheers.
the message is: * Thread1: Programme received signal: "EXC_BAD_ACCESS" *
while the code does compile well and I can turn the pages (41 in total).
This error is most always caused by trying to call a method on an object that has already been deallocated. One way to diagnose this issue is to use the Zombies template in Instruments. It will give you a dialog (with the call stack) when you message a deallocated object. No matter what the exact cause, this is most certainly related to your memory management.
This is a guess.
You said that it crashes if you click next, then back twice.
I'm assuming that you keep the pages in an array, correct? If so, by clicking back twice you are trying to load a page with an index of -1. An array doesn't have an object at the index -1.
If I'm right, All you have to do is this:
// In the back button code:
if(currentPageIndex - 1 < 0) {
// Dont go back
} else {
// Go Back
}
I'm having a problem with a Core Data project on the iPhone. The scenario occurs when a user starts to add an object, then cancels during the process.
If the user hits cancel and returns to the list of objects, a dummy object is listed there, representing the one they were in the middle of creating. This is never saved to the database - saves occur as expected when the user hits the save button.
When the view controller where the user adds data is loaded, I create a new Thing object - this is the Core Data entity that I am adding:
myThing = [NSEntityDescription insertNewObjectForEntityForName:#"myThing" inManagedObjectContext:managedObjectContext];
I tried to delete this in my cancel method as follows:
[managedObjectContext deleteObject:myThing];
When I do this, I get a EXC_BAD_ACCESS when I hit cancel. Stepping through the code in the debugger, it gets through the cancel method fine, but this is being generated in the root view controller where I list my objects and also where I was before I tried to create this object.
All I'm trying to achieve is allowing the user to add a new object, but cancel part-way through.
Any ideas what is causing this error? I am unable to generate a stack trace from this unfortunately :(
Your approach to the object cancel is typical and appropriate.
Memory errors are common and can be tough to debug. Have you run the static analyzer? You may want to set your "myThing" reference to nil after deleting it from the context.
Do you know for sure that it is the cancel workflow that is leading to the memory error?
You can also turn on NSZombie and find out what released object is being accessed. That will help you quickly track this issue down. Google NSZombie for a few examples of how to use it.