-[MyDictationController respondsToSelector:] message sent ot deallocated instance - ios

My app crashes with this stack trace:
[DictationDetailsController respondsToSelector:]: message sent to deallocated instance
I tracked that on instruments trying to see the relevant code causing the crash:
here is the relevant code for MyDictationController in the didSelectRowAtIndexPath: delegate method:
- (void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath {
DictationDetailsController *controller = GET_CONTROLLER_WITH_CLASS([DictationDetailsController class]);
controller.dictation = [unSubmittedDictations objectAtIndex:indexPath.row];
controller.isEditMode = YES;
controller.selectedDate = _selectedDate;
controller.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:controller animated:YES];
}
#property (copy ,nonatomic) Dictation *dictation;
Also i have used #synthesize. Help me out in this issue, to get which deallocated method is being called.?
Here's my DictationDetailsController interface:
#interface DictationDetailsController : BaseController
#property (copy ,nonatomic) Dictation *dictation;
#property (nonatomic) BOOL isEditMode;
#property (nonatomic) NSDate *selectedDate;
#property (weak, nonatomic) IBOutlet UILabel *navigationTitleLabel;
#property (weak, nonatomic) IBOutlet UITextField *patientNameTextField;
#property (weak, nonatomic) IBOutlet UITextField *accountIDTextField;
#property (weak, nonatomic) IBOutlet UITextField *workTypeTextField;
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *deleteButtonWidth;
#property (weak, nonatomic) IBOutlet UIView *tutorialView;
#property (weak, nonatomic) IBOutlet UIView *audioContainer;
#property (weak, nonatomic) IBOutlet UISlider *audioSlider;
#property (weak, nonatomic) IBOutlet UILabel *durationLabel;
#property (weak, nonatomic) IBOutlet UILabel *noRecordingLabel;
#property (weak, nonatomic) IBOutlet UIButton *playPauseButton;
#end
And in dealloc method:
- (void)dealloc {
[player pause];
player = nil;
self.dictation = nil;
}

My guess is the issue is somewhere inside GET_CONTROLLER_WITH_CLASS method. Pop a breakpoint on that line and step over it. It's possibly producing a released instance of the class. That being the case, the crash would occur on the line immediately following the call to that method when it tries to access the dictation property.

Related

How do I fix the error "Expected Expression"

So I was making an app on Xcode ( Objective C) and I really am not able to find a way to fix it
Can somebody please help me with this?
#import "ViewController.h"
#import "DistanceGetter/DGDistanceRequest.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UITextField *startLocation;
#property (nonatomic) DGDistanceRequest *req;
#property (weak, nonatomic) IBOutlet UITextField *endLocationA;
#property (strong, nonatomic) IBOutlet UIView *distanceA;
#property (weak, nonatomic) IBOutlet UITextField *endLocationB;
#property (weak, nonatomic) IBOutlet UILabel *distanceB;
#property (weak, nonatomic) IBOutlet UITextField *endLocationC;
#property (weak, nonatomic) IBOutlet UILabel *distanceC;
#property (weak, nonatomic) IBOutlet UIButton *calculateButton;
#end
#implementation ViewController
- (IBAction)calculateButtonTapped:(id)sender {
self.calculateButton.enabled=NO;
self.req = [DGDistanceRequest alloc];
NSString *start = self.startLocation.text;
NSString *destA = self.endLocationA.text;
NSString *destB = self.endLocationA.text;
NSString *destC = self.endLocationA.text;
NSArray *dests = #[destA,destB,destC];
self.req = [self.req initWithLocationDescriptions:dests
sourceDescription:start];
self.req.callback= void(ˆNSArray *responses)
self.distanceC.text=#"callback";
self.calculateButton.enabled = YES;
self.req=nil;
When I make it ˆvoid(NSArray.....) it gives even more errors
You have a typo :
void(^... should be ^void(... - the error is somewhat misleading, and it seems strange than Xcode didn’t suggest a „Fix-it”.
Anyway, I recommend http://goshdarnblocksyntax.com/ to remind yourself with block syntax.

Array of UIButtons return error

I have an array of UIButton objects (I have 5 buttons so I wanted to store them in an array for easy processing). But Array give me error
"Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[__NSArray0 addObject:]:
unrecognized selector sent to instance"
#property (weak, nonatomic) IBOutlet UIButton *starOne;
#property (weak, nonatomic) IBOutlet UIButton *starTwo;
#property (weak, nonatomic) IBOutlet UIButton *starThree;
#property (weak, nonatomic) IBOutlet UIButton *starFour;
#property (weak, nonatomic) IBOutlet UIButton *starFive;
#property (nonatomic, copy) NSMutableArray *_starButtons;
I have below code in viewDidLoad method
- (void)viewDidLoad {
self._starButtons=[[NSMutableArray alloc]init];
[self._starButtons addObject:self.starOne];
[self._starButtons addObject:self.starTwo];
[self._starButtons addObject:self.starThree];
[self._starButtons addObject:self.starFour];
[self._starButtons addObject:self.starFive];
NSLog(#"%#",self._starButtons);
}
Please help me where i am going wrong.
First remove copy from declaration of array property, make it strong.
Second thing as you have said in comment that you have programmatically created buttons then you not need IBOutlets. So, remove IBOutlets from all properties of button.
Your declaration should like,
#property (weak, nonatomic) UIButton *starOne;
#property (weak, nonatomic) UIButton *starTwo;
#property (weak, nonatomic) UIButton *starThree;
#property (weak, nonatomic) UIButton *starFour;
#property (weak, nonatomic) UIButton *starFive;
#property (nonatomic, strong) NSMutableArray *_starButtons;
Try this:
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UIButton *one;
#property (weak, nonatomic) IBOutlet UIButton *two;
#property (weak, nonatomic) IBOutlet UIButton *three;
#end
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray *buttonArray = [[NSMutableArray alloc] initWithObjects:one,two,three,nil];
NSLog(#"%#",buttonArray);
}
If you're using Storyboard or Nib file then:
Another approach is to connect the UIButtons' to an NSArray of IBOutletCollection in Interface Builder, instead of adding manually each button to an NSMutableArray. Something like this for all UIButtons'.
#property (nonatomic, retain) IBOutletCollection(UIButton) NSArray *buttonsArray;
Just one change in code.
Replace this line:
#property NSMutableArray *_starButtons;

Access Variable Dynamically

I have many buttons named like this:
#property (weak, nonatomic) IBOutlet UIButton *Round1Num1;
#property (weak, nonatomic) IBOutlet UIButton *Round1Num2;
#property (weak, nonatomic) IBOutlet UIButton *Round1Num3;
#property (weak, nonatomic) IBOutlet UIButton *Round1Num4;
#property (weak, nonatomic) IBOutlet UIButton *Round2Num1;
#property (weak, nonatomic) IBOutlet UIButton *Round2Num2;
#property (weak, nonatomic) IBOutlet UIButton *Round2Num3;
#property (weak, nonatomic) IBOutlet UIButton *Round2Num4;
and so on.
I was wondering if I could access them dynamically using stringWithFormat or a similar method.
Example (Sorry if the code is wrong!):
Instead of self.Round1Num1 I could call self.[NSString stringWithFormat:#"Round%dNum%d", 1, 1]
You could use -performSelector::
NSString *round2Num1ButtonAccessorSelectorStr = [NSString stringWithFormat:#"Round%dNum%d", 2, 1];
SEL selector = NSSelectorFromString(round2Num1ButtonAccessorSelectorStr);
if ([self respondsToSelector:selector])
UIButton *round2Num1Button = [self performSelector:selector];
For context, [self performSelector:#selector(someSelector)] is essentially the equivalent to self.someSelector (in the case of a property accessor) which resolves to [self someSelector]. All cases actually call the same runtime function, objc_msgSend(self, someSelector).
Specifically in this context, we're creating a local variable that points to the same reference concealed by the respective IBOutlet property on the VC instance. If the property doesn't exist, then neither will the selector (most likely) so you need to safeguard from an unrecognized selector exception via -respondsToSelector:.

Use Of Undeclared Identifier in my function

I'm having a use of undeclared identifier even though that I declared it in the .h and synthesize in the .m.
I had another problem before, but I posted a question in stack overflow and they said that I shouldn't extern them and when I extered them the code gave me an error "ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)" and know I didn't and it's giving me "Use Of Undeclared Identifier" as you can see
.h
#import <UIKit/UIKit.h>
BOOL OFrameIsHidden, XFrameIsHidden;
NSString *topOne, *topTwo, *topThree;
NSString *midOne, *midTwo, *midThree;
NSString *botOne, *botTwo, *botThree;
void hideAll(void);
#interface ViewController : UIViewController
void hideAll(void);
#property (weak, nonatomic) IBOutlet UIImageView *XFrame;
#property (weak, nonatomic) IBOutlet UIImageView *OFrame;
#property (weak, nonatomic) IBOutlet UIImageView *frame;
#property (weak, nonatomic) IBOutlet UILabel *X;
#property (weak, nonatomic) IBOutlet UILabel *O;
#property (weak, nonatomic) IBOutlet UILabel *WhoWon;
#property (weak, nonatomic) IBOutlet UIButton *oneOne;
#property (weak, nonatomic) IBOutlet UIButton *oneTwo;
#property (weak, nonatomic) IBOutlet UIButton *oneThree;
#property (weak, nonatomic) IBOutlet UIButton *twoOne;
#property (weak, nonatomic) IBOutlet UIButton *twoTwo;
#property (weak, nonatomic) IBOutlet UIButton *twoThree;
#property (weak, nonatomic) IBOutlet UIButton *threeOne;
#property (weak, nonatomic) IBOutlet UIButton *threeTwo;
#property (weak, nonatomic) IBOutlet UIButton *threeThree;
#end
.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize XFrame, OFrame, frame, X, O, WhoWon;
#synthesize oneOne, oneTwo, oneThree;
#synthesize twoOne, twoTwo, twoThree;
#synthesize threeOne, threeTwo, threeThree;
void hideAll(void){
[OFrame setHidden:YES];
[XFrame setHidden:YES];
[frame setHidden:YES];
[X setHidden:YES];
[O setHidden:YES];
[oneOne setHidden:YES];
[oneTwo setHidden:YES];
[oneThree setHidden:YES];
[oneOne setHidden:YES];
[twoTwo setHidden:YES];
[twoThree setHidden:YES];
[threeOne setHidden:YES];
[threeTwo setHidden:YES];
[threeThree setHidden:YES];
}
For your information there is some more code for the IBAcions, but I don't want to make this long.
Don't mix functions and methods like this. It doesn't really help you and all you have done is create visibility issues.
Methods work by passing a hidden parameter which gives access to self. All of your #property definitions are instance variables, so you need access to self to get to them. Functions, like your hideAll, don't have this access so they can't get to the instance variables (they don't know what an instance is).
You generally also don't want variables defined outside the class definition.
Bring your variables into the class or move them to another more appropriate class and use methods for your code, not functions.

Message Sent to Deallocated Instance when adding storyboard view as a subview

Okay, I have a basic understanding of what is happening here, but am having trouble fixing it. I am hoping someone can walk me through what I'm doing wrong here...
I have a nifty app that works great and was built with the storyboard and custom UIViewControllers to handle all my code. I was doing really well, until I needed to handle my push notifications by dropping me in a specific view and loading some data. I made a lot of headway today and just got stuck in a bad way. I am now getting an objc_sendmsg error and I know it has to do with my memory management. I've never initialized a view in this way, so I'm wondering if that's what's causing it. Basically, I can load a view, but I can never push any buttons or get anywhere after that.
Here's the code:
AppDelegate.m
UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *detailVC = [storyBoard instantiateViewControllerWithIdentifier:#"Leads_Calls_SB"];
[self.window addSubview:detailVC.view];
[[NSNotificationCenter defaultCenter] postNotificationName:#"callReceived"
object:nil
userInfo:userInfo];
[self.window makeKeyAndVisible];
Leads_CallsDetailViewController.h
#property (strong, nonatomic) IBOutlet UILabel *cName;
#property (strong, nonatomic) IBOutlet UILabel *cStart;
#property (strong, nonatomic) IBOutlet UILabel *cNumber;
#property (strong, nonatomic) IBOutlet UILabel *cStart2;
#property (strong, nonatomic) IBOutlet UILabel *cEnd;
#property (strong, nonatomic) IBOutlet UILabel *cDuration;
#property (strong, nonatomic) IBOutlet UILabel *cStatus;
#property (strong, nonatomic) IBOutlet UILabel *cProvider;
#property (strong, nonatomic) IBOutlet UILabel *cLineType;
#property (strong, nonatomic) IBOutlet UILabel *cCity;
#property (strong, nonatomic) IBOutlet UIView *innerView;
#property (strong, nonatomic, retain) IBOutlet UIButton *backStyle;
#property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
#property (strong, nonatomic, retain) NSString *cNotifID;
#property (strong, nonatomic, retain) NSString *cNameText;
#property (strong, nonatomic, retain) NSString *cNumberText;
#property (strong, nonatomic, retain) NSString *cStartText;
#property (strong, nonatomic, retain) NSString *cEndText;
#property (strong, nonatomic, retain) NSString *cCallStatusText;
#property (strong, nonatomic, retain) NSString *cLatitudeText;
#property (strong, nonatomic, retain) NSString *cLongitudeText;
#property (strong, nonatomic, retain) NSString *cCityText;
#property (strong, nonatomic, retain) NSString *cLineTypeText;
#property (strong, nonatomic, retain) NSString *cProviderNameText;
- (IBAction)back:(id)sender;
#property (strong, nonatomic) IBOutlet MKMapView *map;
- (IBAction)forward_lead:(id)sender;
- (IBAction)call_lead:(id)sender;
- (IBAction)add_lead:(id)sender;
#property (strong, nonatomic) IBOutlet UIButton *bottomMessage;
#property (strong, nonatomic) IBOutlet UIButton *bottomCalls;
#property (strong, nonatomic) IBOutlet UIButton *bottomReports;
#property (strong, nonatomic) IBOutlet UIButton *bottomHome;
.m
- (IBAction)back:(id)sender {
if (self.cNotifID != nil)
{
[self.view removeFromSuperview];
}
else {
[self.navigationController popViewControllerAnimated:YES];
}
}
I'm not sure what I'm doing wrong, but no matter what happens if I hit any button on that page or try to dismiss the view, it screams at me and gets angry...I've tried everything I can think of to figure this out.
Thanks guys!
The issue is that you're creating your view controller, grabbing its view, but the letting the controller fall out of scope (and presumably using ARC where it's getting released on you).
In my original answer, I thought the goal was simply to consider different ways of presenting the standard initial view controller. But that is not the case. The question is how to present a new scene when some event takes place (in my example, I'm doing it upon openURL, but you could presumably do this in response to notifications and the like).
Anyway, one approach to solving this is to perform presentViewController. So you could do something like:
// determine the current controller (in case you've already done some modal segues)
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIViewController *currentController = window.rootViewController;
while (currentController.presentedViewController)
currentController = currentController.presentedViewController;
// load the controller for the new scene
UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *newController = [storyBoard instantiateViewControllerWithIdentifier:#"Leads_Calls_SB"];
// perform a modal transition to the new scene
[currentController presentViewController:newController animated:NO completion:nil];

Resources