SliderValueChanged unrecognized selector sent to instance crashes app - ios

I have a UIViewController QuoteViewController that has a UITableView. Inside the UITableView is a custom UITableViewCell called excessTableViewCell.
In story board I have created a custom tableview cell and assigned the custom class to excessTableViewCell and I have hooked the slider IBAction up with a ValideDidChange
This is what excessTableViewCell.m looks like.
#import "ExcessTableViewCell.h"
#implementation ExcessTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
self.excessLabel.text = [NSString stringWithFormat:#"$ %#", self.excessString];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
self.selectionStyle = UITableViewCellSelectionStyleNone;
}
- (IBAction)excessValueChanged:(UISlider *)sender
{
UISlider *MySlider = (UISlider *)sender;
int SliderValue = (int)(MySlider.value/10) * 10;
self.excessLabel.text = [NSString stringWithFormat:#"$ %d", SliderValue];
}
#end
This is what my QuoteViewController tableview cell for row looks like.
// slider
NSString *cellIDString = #"excessCell1";
self.excessTableViewCell = [tableView dequeueReusableCellWithIdentifier:cellIDString forIndexPath:indexPath];
// Configure the cell...
self.excessTableViewCell.excessSlider.maximumValue = 2000;
self.excessTableViewCell.excessSlider.value = 2000 / 2;
NSInteger halfValue = 2000 / 2;
self.excessTableViewCell.excessLabel.text = [NSString stringWithFormat:#"$ %ld", (long)halfValue];
return self.excessTableViewCell;
Effectively as soon as I try to slide the value the app crashes and produces the following error.
This is what my error looks like:
2017-04-08 17:12:08.863831 Insuriato[17401:3848405]
-[QuoteViewController sliderValueChanged:]: unrecognized selector sent to instance 0x1005423f0 2017-04-08 17:18:57.449734 Insuriato[17401:3848405] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[QuoteViewController sliderValueChanged:]: unrecognized selector sent to instance 0x1005423f0'
*** First throw call stack: (0x1860f51b8 0x184b2c55c 0x1860fc268 0x1860f9270 0x185ff280c 0x18bfdfd30 0x18bfdfcb0 0x18bfca128 0x18c387758 0x18bfe7974 0x18c56a628 0x18c5666c0 0x18c5661e0 0x18c56549c 0x18bfda30c 0x18bfaada0 0x18c79475c 0x18c78e130 0x1860a2b5c 0x1860a24a4 0x1860a00a4 0x185fce2b8 0x187a82198 0x18c0157fc 0x18c010534 0x100087a3c 0x184fb15b8) libc++abi.dylib: terminating with uncaught exception of type NSException

Related

Receive NSRangeException error message "objectAtIndex beyond bounds"

In one class called LevelSelectViewController, I have this public property
#property (nonatomic, strong, getter=getLevelNumber) NSNumber *levelNumber;
which stores an int value based on a UIButton* touch selection using the method
- (IBAction)buttonPressedSoWhatNumber:(id)sender
{
UIButton *button = (UIButton *)sender;
int row = button.tag;
_levelNumber = [NSNumber numberWithInt:row];
}
When I put a breakpoint at the end of the method to see if my touch interaction triggers the correct result based on what I coded (when I press button 1, really), _levelNumber reads 0 (which it should). I also have a getter method written out for it.
Now, in this second class called GameViewController, I have a method setUpBoards which (should) obtain that value for *levelNumber. It looks like this:
- (void)setUpBoards {
LevelSelectViewController* level = [[LevelSelectViewController alloc] init];
[level getLevelNumber];
[self createLevelModel:(int)level];
}
In that same class, the method createLevelModel:(int)levelIndex uses that value to be passed to 5 initialization methods that access a Levels.plist file to load data for my game.
Basically, that number represents what level button I pressed and uses that number to load the correct level. In another manner, I have verified that those 5 initialization methods work along with loading data from my Levels.plist file.
Now, between the transition from LevelSelectViewController to GameViewController, I receive the NSRangeException error message:
'NSRangeException', reason: '-[__NSCFArray objectAtIndex:]: index (554166800) beyond bounds (1)'
even when pressing the 1 button (which should work considering I only have Item 0 in my plist typed out.......which, again, I verified worked using another manner).
TO ADD ON TO THIS. Here's another important method:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = #"cvCell";
CVCell *cell = (CVCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
NSMutableArray *data = [self.dataArray objectAtIndex:indexPath.section];
NSString *cellData = [data objectAtIndex:indexPath.row];
[cell.buttonClick setTag:indexPath.row];
[cell.buttonClick addTarget:self action:#selector(buttonPressedSoWhatNumber:)
forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:cell.buttonClick];
return cell;
}
Any insight?
Here's the push controller method from LevelSelectViewController to GameViewController:
-(IBAction)buttonPressed:(id)sender {
GameViewController* obj = [[GameViewController alloc] initWithNibName:#"GameViewController" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
}
buttonPressed: is another method given to the UIButton*
You need a simple int property in LevelSelectViewController that you can use to store the level that has been selected:
#property int levelSelected;
The store the selected value in your button press handler:
- (IBAction)buttonPressedSoWhatNumber:(UIButton *)sender
{
self.levelSelected = sender.tag;
}
Then you can pass this to a corresponding int property on your GameViewController;
-(IBAction)buttonPressed:(id)sender {
GameViewController* obj = [[GameViewController alloc] initWithNibName:#"GameViewController" bundle:nil];
obj.level = self.selectedLevel
[self.navigationController pushViewController:obj animated:YES];
}
The problem is that you are casting a pointer to an int.
#property (nonatomic, strong, getter=getLevelNumber) NSNumber *levelNumber;
Defines a pointer to an object of type NSNumber.
[self createLevelModel:(int)level];
Is casting that NSNumber * to an int.
You also have another bug in that you are setting level as the view controller and calling getLevelNumber but not actually using the returned value. So here is what I would do. Firstly you don't need to define an NSNumber and don't need a custom getter. Just use this:
#property (nonatomic, assign) int levelNumber;
Then this becomes much simple:
- (void)setUpBoards {
LevelSelectViewController* levelSelectViewController = [[LevelSelectViewController alloc] init];
[self createLevelModel: levelSelectViewController.levelNumber]; // Always going to be zero at this point.
}

Is it possible to call a performSegueWithIdentifier from another class?

I just build a class to manage correctly my database and JSON request. The problem is that now, how can I perform the segue ?
Here is my code
In my view :
- (IBAction)loginClick:(id)sender
{
NSString *post = [NSString stringWithFormat:#"username=test&password=test"];
[[DataManagement sharedManager] WebServiceLogin:post];
}
- (void) showTypeView
{
[self performSegueWithIdentifier:#"showTypeView" sender:nil];
}
In my class :
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
...
switch ([[response valueForKey:#"success"] intValue])
{
case 0:
{
NSLog(#"error: %# error Description: %#", [response valueForKey:#"success"], [response valueForKey:#"error_message"]);
break;
}
case 1:
{
LoginViewController *showView = [LoginViewController new];
[showView showTypeView];
break;
}
default:
break;
}
...
}
When I launch, I have an error :
**
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<LoginViewController: 0x165afd30>) has no segue with identifier 'showTypeView''
*** First throw call stack:
(0x2592e2eb 0x250fadff 0x29e2b037 0xe1819 0xdb64f 0x25f64de1 0x25f64d99 0x25f64e8d 0x25e261ef 0x25edf04f 0xa77cab 0xa7f835 0x25e171e3 0x258415f9 0x25e170cb 0x25e16f95 0x25e16e29 0x258f1257 0x258f0e47 0x258ef1af 0x25841bb9 0x258419ad 0x26abbaf9 0x29b2dfb5 0xe3ea9 0x254f4873)
libc++abi.dylib: terminating with uncaught exception of type NSException
**
If you're using segueWithIdentifier then you need to already have the segue built in Storyboard and labeled correctly as "showTypeView". Otherwise you should use a navigation controller to push a view controller or use self presentViewController to show a modal view controller.
EDIT:
Building off of Larme's comment, you can build a delegate like this:
// In your class.h file
#property (weak, nonatomic)id<SegueDelegate> delegate;
// In class.m file
LoginViewController *showView = [LoginViewController new];
self.delegate = showView;
[self.delegate segue];
// In LoginViewController.h
#protocol SegueDelegate
-(void)segue;
#end
#interface LoginViewController: UIViewController <SegueDelegate>
-(void)segue;
#end
// In LoginViewController.m
#implementation LoginViewController
-(void)segue
{
[self performSegueWithIdentifier:#"showTypeView" sender:nil];
}
#end

Unrecognized selector sent to an instance?

I have three methods which are taking parameters,
I am taking exception at this parameter giving,
[QuestionnaireView continueSingle:withQuestion:question:]: unrecognized selector sent to instance 0x8a4b1c0
What am i doing wrong? Its definition is also given in the header file.
Here is my code;
-(void) continueSingle:(id)sender withQuestion:(Question*)quest{
int counter = 0;
NSString * tempAnswer;
for(UIView* subview in [sender superview].subviews)
{
if([subview isKindOfClass:[UIButton class]])
{
if([((UIButton*)subview) isSelected])
{
counter++;
tempAnswer = [NSString stringWithFormat:#"%#",((UIButton*)subview).currentTitle];
}
}
}
}
Your mistake is here
-(void) continueSingle:(id)sender withQuestion:(Question*)quest
Because you are passing three parameter but you're receiving only two parameter. So you need to take 3 parameter. Like this..
-(void) continueSingle:(id)sender withQuestion:(Question*)quest question:(Question *)question1

issue with unrecognized selector sent to instance

I'm using the master detail template.
Header file MasterViewController.h:
#import <UIKit/UIKit.h>
//(Imported both MasterViewController.h and DetailViewController.h in implementation file of MasterViewController.m)
#class DetailViewController;
#interface MasterViewController : UITableViewController
#property (strong, nonatomic) DetailViewController *detailViewController;
-(void)createFlowerData;
#end
Implementation file HeaderViewController.m:
#interface MasterViewController () {
NSMutableArray *_objects;
NSArray *_flowerData;
NSArray *_flowerSections;
}
#end
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
//invoking the method I implemented to give data to flowerData array
[self createFlowerData];
}
-(void)createFlowerData{
NSMutableArray *redFlowers;
NSMutableArray *blueFlowers;
redFlowers = [[NSMutableArray alloc] init];
blueFlowers = [[NSMutableArray alloc] init];
//create the 2 sections for the flowerSections array
_flowerSections = #[#"Red Flowers", #"Blue Flowers"];
//add the objects to the mutable array
//red flowers
[redFlowers addObject:#{#"name":#"Poppy",#"picture":#"Poppy.png",#"url":#"http://en.wikiepdia.org/wiki/Poppy"}];
[redFlowers addObject:#{#"name":#"Tulip",#"picture":#"Tulip.png",#"url":#"http://en.wikipedia.org/wiki/Tulip"}];
[redFlowers addObject:#{#"name":#"Gerbera",#"picture":#"Gerbera.png",#"url":#"http://en.wikiepdia.org/wiki/Gerbera"}];
//blue flowers
[blueFlowers addObject:#{#"name":#"Phlox",#"picture":#"Phlox.png",#"url":#"http:en.wikipedia.org/wiki/Gerbera"}];
[blueFlowers addObject:#{#"name":#"Pin Cushion Flower",#"picture":#"Pincushion flower.png",#"url":#"http://en.wikipedia.org/wiki/Scabious"}];
[blueFlowers addObject:#{#"name":#"Iris",#"picture":#"Iris.png",#"url":#"http://en.wikipedia.org/wiki/Iris_(plant)"}];
_flowerData = #[redFlowers, blueFlowers];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [_flowerSections count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//find the number of row elements in a given section of the flower Data array
return [_flowerData[section] count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
//index 0 is the red flower
//index 1 is the blue flower
return _flowerSections[section];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"flowerCell"];
cell.textLabel.text = _flowerData[indexPath.section][indexPath.row][#"name"];
cell.detailTextLabel.text = _flowerData[indexPath.section][indexPath.row][#"url"];
cell.imageView.image = _flowerData[indexPath.section][indexPath.row][#"picture"];
return cell;
}
I then get the following when I build the application on the ios simulator(iPad):
2013-09-01 23:49:40.015 flowerDetail2[2394:c07] -[__NSCFConstantString _isResizable]: unrecognized selector sent to instance 0x6af4
2013-09-01 23:49:40.017 flowerDetail2[2394:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString _isResizable]: unrecognized selector sent to instance 0x6af4'
*** First throw call stack:
(0x1c95012 0x10d2e7e 0x1d204bd 0x1c84bbc 0x1c8494e 0x4ca7ab 0x121ae9 0x2c1f 0xd18fb 0xd19cf 0xba1bb 0xcab4b 0x672dd 0x10e66b0 0x2291fc0 0x228633c 0x2291eaf 0x1062bd 0x4eb56 0x4d66f 0x4d589 0x4c7e4 0x4c61e 0x4d3d9 0x502d2 0xfa99c 0x47574 0x4776f 0x47905 0x8dceab6 0x50917 0x1496c 0x1594b 0x26cb5 0x27beb 0x19698 0x1bf0df9 0x1bf0ad0 0x1c0abf5 0x1c0a962 0x1c3bbb6 0x1c3af44 0x1c3ae1b 0x1517a 0x16ffc 0x1bed 0x1b15)
libc++abi.dylib: terminate called throwing an exception
(lldb)
(Please note that I did not include everything, just the parts I thought were important)
This has been driving me crazy the whole day, I've checked multiple times, rewritten the whole thing and still the same result, I can't even get the cells to display. I googled, and I found something like it means that I'm sending a message to a method that doesn't know what to do with it, but I'm sure it's right? Could somebody please help me debug this!
cell.imageView.image = _flowerData[indexPath.section][indexPath.row][#"picture"];
this line cell.imageView.image expect UIImage type
[redFlowers addObject:#{#"name":#"Gerbera",#"picture":#"Gerbera.png",#"url":#"http://en.wikiepdia.org/wiki/Gerbera"}];
but you give it a NSString here, which of cause will make runtime error.
So should be like this
cell.imageView.image = [UIImage imageNamed:_flowerData[indexPath.section][indexPath.row][#"picture"]];
If you are NOT using ARC: You need to retain each of your dictionaries. Like this redFlowers = [[[NSMutableArray alloc] init] retain]; do that for each of your arrays. Also, NSLog(#"%#", redFlowers) before the line of code where your app crashes and post the output. Replace redFlowers with whatever the dictionary being called next is.
From what i am getting, what you need to do is first make NSDictionary objects and than add those objects to NSMutableArray.
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
[dic setValue:#"Poppy" forKey:#"name"];
[dic setValue:#"Poppy.png" forKey:#"picture"];
[dic setValue:#"http://en.wikiepdia.org/wiki/Poppy" forKey:#"url"];
[redFlowers addObject:dic];
[dic release]; // Dont use this in case of ARC
Repeat this for all three or number of objects you need to add. Hope this helps.

SIGABRT thread error running simple ios app

Ok so there have been a lot of answers to questions like this but none of them have worked for me. Basically i have written a very simple iOS app that has a label and a button. click the button and the label changes. Here is the code
//ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
- (IBAction)buttonPressed:(id)sender;
#property (strong, nonatomic) IBOutlet UILabel *predictionLabel;
#end
//
// ViewController.m
// CrystalBall
//
//
//
#import "ViewController.h"
#implementation ViewController
#synthesize predictionLabel;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setPredictionLabel:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)buttonPressed:(id)sender {
self.predictionLabel.text = #"Definitley Yes!";
}
#end
And when i run it in the simulator the app opens fine and then i click the "Predict" button and then it freezes and this is the error that shows up in green
Thread 1: Program recieved signal: "SIGABRT".
that is along a line that reads
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
The debugger says:
2013-01-19 22:53:30.511 CrystalBall[441:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setText:]: unrecognized selector sent to instance 0x6a19c70'
* First throw call stack:
2013-01-19 22:53:30.511 CrystalBall[441:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setText:]: unrecognized selector sent to instance 0x6a19c70'
*** First throw call stack:
(0x13b9052 0x154ad0a 0x13baced 0x131ff00 0x131fce2 0x2385 0x13baec9 0x135c2 0x1355a 0xb8b76 0xb903f 0xb82fe 0x38a30 0x38c56 0x1f384 0x12aa9 0x12a3fa9 0x138d1c5 0x12f2022 0x12f090a 0x12efdb4 0x12efccb 0x12a2879 0x12a293e 0x10a9b 0x1da8 0x1d05)
terminate called throwing an exception(gdb)
Hopefully that is enough information. Thank you!
'-[UIView setText:]: unrecognized selector sent to instance 0x6a19c70'
means that you are trying to send the setText message to a UIView instance, which does not have any such method.
This possibly comes from the statement:
self.predictionLabel.text = #"Definitley Yes!";
so you should review how you defined predictionLabel and make sure that it is of the correct type.
About the fact that you the debugger is showing you the line:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
you should define an exception breakpoint in Xcode to catch all exceptions:
go to the breakpoints tab in the left-hand pane;
at the bottom of the pane, you will find a + icon;
click it and the select Add exception breakpoint;
confirm and it's done.
Now, the debugger shall stop on the actual line causing sigabrt so you can inspect your objects' state.

Resources