Error while dismissing UITableViewController - ios

I have been creating a project and I am getting a warning from the debugger:
Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress!
Here is the code:
if (self.editHw)
{
if (self.homeworkEdit)
{
[self.homeworkEdit setValue:self.homeworkNameTF.text forKey:#"name"];
[self.homeworkEdit setValue:self.subject forKey:#"subject"];
[self.homeworkEdit setValue:self.dateDueLabel.text forKey:#"due_date"];
[self.homeworkEdit setValue:self.reminderDateLabel.text forKey:#"reminder_date"];
[self.homeworkEdit setValue:self.commentsTF.text forKey:#"comments"];
NSError *error = nil;
[context save:&error];
[self dismissViewControllerAnimated:YES completion:nil];
}
}
Can anyone tell me what the error means and why it is there? If you need any more info just ask.

The code you show isn't enough to know what the error is. The error is shown because you are trying to animate 2 different view controllers at the same time (one being dismissed and one being shown). To avoide the issue you can:
1. Wait until one animation is complete before starting the next
Or
2. Run one of the changes (probably the dismissal) without animation

Related

iMessageExt app Error starting application

I created my iMessage extension, when I try to open it, the first screen appears but it is totally frozen, and it does not react in any way.
I've put logs in the viewDidLoad of that first view and nothing appears there, after a few seconds I can already see those logs.
To make the application freezing lose that status, user has to slide screen left or right and back again.
I've tried looking all over the web for someone who happens to be the same, but I could not find anything.
It does not come to mind more screenshots or portions of code add, if you think I should provide some additional information, just let me know
Any help would be appreciated.
Thank you.
UPDATE:
This is my Project Structure.
This is my viewDidLoad code.
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(#"here viewDidLoad iMessage ext~~~!");
[self applyCornerRadiusToBtn];
[self registerPresentationAction];
NSDictionary *user = [self getUserInfoFromHostApp];
if (user) {
NSLog(#"Here != null user info");
//It is assumed that when you enter this point and run this log, the app should navigate to the next screen, but it does not.
[self performSegueWithIdentifier:#"goToYoutubeListIm" sender:nil];
} else {
NSLog(#"Here userInfo null");
}
}
- (NSDictionary *)getUserInfoFromHostApp
{
NSUserDefaults *myDefaults = [[NSUserDefaults alloc] initWithSuiteName:#"group.com.xxxxx"];
NSDictionary *userNameSaved = [myDefaults objectForKey:#"userInfoExt"];;
NSLog(#"userNameSaved in xxxx Ext ==> %#",userNameSaved);
NSURL *groupURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:#"group.com.xxxx"];
NSLog(#"groupURL ==> %#",groupURL);
return userNameSaved;
}
For all concerned I have found the problem or problems to be accurate.
1) I was creating my controllers type MSMessagesAppViewController. Apparently there should only be one controller of this type.
2) I had logic in the viewDidAppear in my MSMessagesAppViewController. For some strange reason this also caused the problem, I had to get the logic out there and force the user to interact with a button to execute the logic that was in the didAppear

iOS - Show SVProgressHUD message on screen without interrupting user interaction

I'm making a synchronize function that syncs local Core Data with the server. I want to make the synchronizations happen in the background without disrupting user interaction. When I receive the response (whether success or failure) the app should display a message somewhere on the screen to notify the user about the outcome.
UIAlertController is not a good choice because it will block user action.
Currently I'm using SVProgressHUD:
__weak StampCollectiblesMainViewController *weakSelf = self;
if ([[AppDelegate sharedAppDelegate] hasInternetConnectionWarnIfNoConnection:YES]) {
[_activityIndicator startAnimating];
[Stamp API_getStampsOnCompletion:^(BOOL success, NSError *error) {
if (error) {
[_activityIndicator stopAnimating];
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
[SVProgressHUD setAnimationDuration:0.5];
[SVProgressHUD showErrorWithStatus:#"error syncronize with server"];
}
else {
[_activityIndicator stopAnimating];
[featuredImageView setImageWithURL:[NSURL URLWithString:[Stamp featuredStamp].coverImage] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[yearDropDownList setValues:[Stamp yearsDropDownValues]];
[yearDropDownList selectRow:0 animated:NO];
[weakSelf yearDropDownListSelected];
[SVProgressHUD dismiss];
}
}];
}
Is there a modification I can make so the user can still interact with the app? I just want to show the message without taking up too much space. Any help is much appreciated. Thanks.
Looks like the easiest thing will be to use SVProgressHUDMaskTypeNone.
Also check out this issue.
Sorry but you gonna have to build your own custom view.
In fact it's not that difficult. What I would do is simply add a small view on the top of the screen with your custom message and a close button (to allow user to hide quickly the message). This is usually done by adding this new view to the current window, so that it will be on the top of every view and won't block the UI (except the part hidden by that view :) )

iOS, is it ok to pop a ViewController from a navigationController, even if a request called from it isn't finished?

Here is my situation:
I have a viewController whose main goal is to upload one photo. I use ReactiveCocoa like this:
- (IBAction)uploadTapped
{
[[PhotosService uploadSignal] subscribeError:^(NSError *error) {
NSLog(#"%#", error);
} completed:^{
NSLog(#"Upload completed");
}];
//I don't need to wait the upload result
[self.navigationController popViewControllerAnimated:YES];`
}
Is it ok to pop the viewController even if the upload isn't finished? I wouldn't want to risk an EXC_BAD_ACCESS, or a memory leak because of that...
Thank you for your help

remembering state of activity indicator ios

I'm showing a UIActivityIndicator while saving a PFObject (using Parse.com)
- (void) saveNewMessage {
// Show Activity Indicator
UIActivityIndicatorView *activityView=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityView.center=self.view.center;
[activityView startAnimating];
// Create Message
...
// Save Message
[message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
// complete activity indicator
[activityView stop];
}
}];
}
My Problem: What if the user leaves the view while we're still saving, and then comes back to the view and the save hasn't completed yet. The UIActivityIndicatorView will be gone. How do I determine whether the parse operation has completed?
It depends on how you implemented "leaving the view" and "coming back to the view"
If you use the same viewcontroller (for example pushing popping the vc with navigation viewcontroller), UIActivityIndicatorView has a method named
- (BOOL)isAnimating
You can check UIActivityIndicatorView's status
Otherwise (ie you allocate and present a new viewcontroller) you need to use a global mechanism, nsnotificationcenter might suit your needs or you may set a variable in AppDelegate or you can read/write to a local file.
You could store a BOOL in your view controller telling that the save operation has finished, then update it in your completion block along with the [activityView stop];.
Then, to handle the case where the user leaves the screen and comes back later, add a check in - (void)viewWillAppear to also hide the UIActivityIndicatorView if the save operation has completed (e.g. if your BOOL is set to YES).
PFObject actually has a built in boolean to tell us when its done saving. You may also make your save button disabled at the same time just to keep from getting multiple save requests.
[activityView startAnimating]
[yourobject saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error){
if (succeeded) {
[activityView stopAnimating];
}else{
[activityView stopAnimating];
}

How to debug on the iPhone itself without xcode? UISearchBar/DisplayController crashes

I have a problem: I am programming an app that is using a searchBar and a tableView.
When I click the search bar, type some string to search for, as soon as I hit the cancel button, or delete all the search terms and click the tableView again my app crashes.
When I run the app in the iOS Simulator, it doesn't crash when doing this.
When I run the app on my iPhone via xcode, it doesn't crash when doing this.
I don't really understand the device log and I wanted to ask if there is any way to find out what's going terribly wrong and why this is not happening when doing it via xcode. Please help me!
PS: One of the device logs: (Maybe you guys understand this)
EDIT: Here's the code of the searchDisplayControllerDidEndSearch method:
- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
{
[self.navigationController setNavigationBarHidden:NO animated:YES];
[UIView beginAnimations:#"DeactivateSearch" context:nil];
[UIView setAnimationDuration:0.4];
[self.attractionsTableView setFrame:CGRectMake(0, 43, 320, 362)];
[UIView commitAnimations];
NSFetchRequest *fetchRequest = [[self fetchedResultsController] fetchRequest];
[fetchRequest setPredicate:nil];
NSError *error = nil;
if (![[self fetchedResultsController] performFetch:&error]) {
// Handle error
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
[self setSearchIsActive:NO];
return;
}
UPDATE: The search bar does NOT crash if no text was typed. So simply activating the searchBar and deactivating it without typing works. But as soon as I have typed a single character the deactivating process crashes the app.
Look for an animation callback issue. Also there is a console log, look at it.
I found the answer myself..
In one of my custom cells I released something too often and thus the app crashed when the UISearchDisplayController was releasing the UITableView for the search results.

Resources