I have an issue when I click on the segment controller in the simulator.
Here's my code
#import "ViewController.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UITextField *inputField;
#property (weak, nonatomic) IBOutlet UILabel *outputField;
#property (weak, nonatomic) IBOutlet UISegmentedControl *segmentController;
#end
#implementation ViewController
- (IBAction)updateButton:(id)sender {
NSMutableString *buf = [NSMutableString new];
switch (self.segmentController.selectedSegmentIndex) {
case 0:
[buf appendString: #"unit two"];
break;
case 1:
[buf appendString: #"unit three"];
break;
default:
[buf appendString: #"unit four"];
break;
}
self.outputField.text = buf;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Here's the error I get:
2016-07-29 17:40:45.506 UnitConverter[3213:534645] -[ViewController segmentController:]: unrecognized selector sent to instance 0x7fae71dbd040 2016-07-29 17:40:45.509 UnitConverter[3213:534645] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController segmentController:]: unrecognized selector sent to instance 0x7fae71dbd040'
It's looking for the method segmentController, but your class doesn't have one. Right click on the Segment Controller in IB and remove and re-add the connection to. You may have more than one Action connected. Click the little X to remove them.
- (IBAction)updateButton:(id)sender
Related
I'm just starting to learn iOS development and Objective C and I'm following Apple's tutorial (https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/ThirdTutorial.html#//apple_ref/doc/uid/TP40011343-CH10-SW1)
I have a text field that adds a new task to an array. When I press "done" the task is added to the array and it appears in the tableview - but then i get this in the debug:
[XYZViewController addTaskField:]: unrecognized selector sent to instance 0x7fb13348c8c0
2014-10-16 18:00:36.120 Tutorial123[7880:1837804] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[XYZViewController addTaskField:]: unrecognized selector sent to instance 0x7fb13348c8c0'
Here's the code I have on that file that handles the text field:
#import "XYZViewController.h"
#import "ToDoItem.h"
#interface XYZViewController ()
#property (weak, nonatomic) IBOutlet UITextField *addTaskField;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *doneButton;
#end
#implementation XYZViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if(sender != self.doneButton) return;
if(self.addTaskField.text.length > 0){
self.todoItem = [[ToDoItem alloc] init];
self.todoItem.itemName = self.addTaskField.text;
self.todoItem.completed = NO;
}
}
#end
When you were wiring addTaskField button from storyboard did you create an action first then deleted the method in the code and created an outlet? If that's what happened you have to go back to storyboard click on the button and connection inspector and see that touch up inside doesn't have addTaskField: wired up. See image below. I added testAction: action. You have to press the little x next to View Controller testAction: to delete it. Let me know if that's what happened.
I am facing an issue which I have tried to resolve but am yet to find a solution. I am using Xcode4.5 and iOS 6.This is my code:
viewController.h file:
#import <UIKit/UIKit.h></i>
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UISegmentedControl *colorChoice;
#property (weak, nonatomic) IBOutlet UIWebView *flowerView;
#property (weak, nonatomic) IBOutlet UIWebView *flowerDetailView;
- (IBAction)toggleFlowerdetail:(id)sender;
- (IBAction)getFlower:(id)sender;
#end
viewController.m files
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction)toggleFlowerdetail:(id)sender {
self.flowerDetailView.hidden = [sender isOn];
}
- (IBAction)getFlower:(id)sender {
NSURL *imageURL;
NSURL *detailURL;
NSString *imageURLString;
NSString *detailURLString;
NSString *color;
int sessionID;
color = [self.colorChoice titleForSegmentAtIndex:self.colorChoice.selectedSegmentIndex];
sessionID = random()%50000;
imageURLString = [[NSString alloc] initWithFormat:#"http://floraphotographs.com/showrandomios.php?color=%#&session=%d",color,sessionID];
detailURLString = [[NSString alloc] initWithFormat:#"http://www.floraphotographs.com/details.php?session=%d",sessionID ];
imageURL = [[NSURL alloc]initWithString:imageURLString];
detailURL = [[NSURL alloc]initWithString:detailURLString];
[self.flowerView loadRequest:[NSURLRequest requestWithURL:imageURL]];
[self.flowerDetailView loadRequest:[NSURLRequest requestWithURL:detailURL]];
self.flowerDetailView.backgroundColor = [UIColor clearColor];
}
#end
My Error:
FlowerWeb[4784:11303] *** Terminating app due to uncaught exception
'NSUnknownKeyException', reason: '[
setValue:forUndefinedKey:]: this class is not key value
coding-compliant for the key detail.'
Any Help will appreciated. Thanks
In storyboard, check your view controller, it is connected to a property called detail.
But that property is being removed in that view controller class.
Check your xib. This might be because you accidentally removed an IBOutlet object while it was still attached to your xib file.
Check out this post as well:-
"* Assertion failure in -[PlayingCell layoutSublayersOfLayer:],
/SourceCache/UIKit_Sim/UIKit-2372/UIView.m:5776 2013-11-01
18:44:12.526 SnapTrack[216:c07] * Terminating app due to uncaught
exception 'NSInternalInconsistencyException', reason: 'Auto Layout
still required after executing -layoutSubviews. PlayingCell's
implementation of -layoutSubviews needs to call super.'"
I'm trying to run my app (which I designed for iOS7) in the iOS6 simulator. My project contains a TabBarController. In the first view controller in the tabbarcontroller I have a table view containing custom UITableViewCell's. They load without a problem. However, when I switch to another tab, where I have another table view, also with custom cells, I get the error posted above. The viewControllers are set up almost identically (both have subviews organized with auto layout). Has anyone seen this exception/know how to address it?
Thanks!
EDIT: Code for PlayingCell.
#import <UIKit/UIKit.h>
#interface PlayingCell : UITableViewCell
#property (strong, nonatomic) IBOutlet UILabel *lblTrackNum;
#property (strong, nonatomic) IBOutlet UIImageView *albumArt;
#property (strong, nonatomic) IBOutlet UILabel *lblSongTitle;
#property (strong, nonatomic) IBOutlet UILabel *lblAlbumTitle;
#property (strong, nonatomic) IBOutlet UILabel *lblArtist;
#property (strong, nonatomic) IBOutlet UIImageView *imgPlay;
#property (strong,nonatomic) NSMutableDictionary *songInfo;
- (IBAction)downloadBtnPressed:(id)sender;
#end
#import "PlayingCell.h"
#implementation PlayingCell
#synthesize songInfo;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (IBAction)downloadBtnPressed:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[songInfo objectForKey:#"trackViewUrl"]]];
NSLog(#"%#",[songInfo objectForKey:#"trackViewUrl"]);
}
-(void)layoutSubviews
{
[super layoutSubviews];
}
Do what the error states. In one of your custom cell classes you appear to be overriding the layoutSubviews method. You must call [super layoutSubviews] in your implementation. This is typically the 1st line.
- (void)layoutSubviews {
[super layoutSubviews];
// the rest of your custom layout code
}
I just created a Xib with the Interface for an Audioplayer (Play-Button, Stop-Button, Volume-Slider, Time-Slider). I connected the Files owner to the AudioPlayerViewController and created some Outlets from the Objects and IB Action, by connecting to the ViewController.
Now I'm adding this ViewControllers View as a Subview in an UIScrollview. If I now Use one of these Objects I receive different Errors:
First the Time-Slider. There Exist a IBAction for value Changed:
2013-06-23 14:14:55.448 Bookshelf[17323:907] -[__NSMallocBlock__ CurrentPlayTimeChanged:]: unrecognized selector sent to instance 0x1dd69500
2013-06-23 14:14:55.450 Bookshelf[17323:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSMallocBlock__ CurrentPlayTimeChanged:]: unrecognized selector sent to instance 0x1dd69500'
*** First throw call stack:
(0x31e1d2a3 0x39cd897f 0x31e20e07 0x31e1f531 0x31d76f68 0x33d100c5 0x33d10077 0x33d10055 0x33d0f90b 0x33df0d07 0x33d0f507 0x33c2e421 0x31df26cd 0x31df09c1 0x31df0d17 0x31d63ebd 0x31d63d49 0x3592f2eb 0x33c79301 0x680dd 0x3a10fb20)
libc++abi.dylib: terminate called throwing an exception
Second The Buttons:
2013-06-23 14:16:36.842 Bookshelf[17339:907] -[__NSArrayM AudioStopped:]: unrecognized selector sent to instance 0x1fdb1480
2013-06-23 14:16:36.844 Bookshelf[17339:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM AudioStopped:]: unrecognized selector sent to instance 0x1fdb1480'
*** First throw call stack:
(0x31e1d2a3 0x39cd897f 0x31e20e07 0x31e1f531 0x31d76f68 0x33d100c5 0x33d1014d 0x33d100c5 0x33d10077 0x33d10055 0x33d0f90b 0x33d0fe01 0x33c385f1 0x33c25801 0x33c2511b 0x359305a3 0x359301d3 0x31df2173 0x31df2117 0x31df0f99 0x31d63ebd 0x31d63d49 0x3592f2eb 0x33c79301 0xa0dd 0x3a10fb20)
libc++abi.dylib: terminate called throwing an exception
Third The Volume Slider:
The ViewController .h :
#import <UIKit/UIKit.h>
#interface AudioPlayerViewController : UIViewController {
NSURL * fileURL;
}
#property (weak, nonatomic) IBOutlet UISlider *volumeSlider;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *AudioStopButton;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *AudioPlay_PauseButton;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *AudioTimeLabel;
#property (weak, nonatomic) IBOutlet UISlider *TimeLineSlider;
#property (nonatomic, strong) NSURL * fileURL;
- (IBAction)volumeChanged:(id)sender;
- (IBAction)AudioStopped:(id)sender;
- (IBAction)AudioPlayPaused:(id)sender;
- (IBAction)TimeLabelPressed:(id)sender;
- (IBAction)CurrentPlayTimeChanged:(id)sender;
#end
The ViewController .m :
#import "AudioPlayerViewController.h"
#interface AudioPlayerViewController ()
#end
#implementation AudioPlayerViewController
#synthesize volumeSlider, AudioPlay_PauseButton, TimeLineSlider, AudioTimeLabel, AudioStopButton;
#synthesize fileURL;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)volumeChanged:(id)sender {
NSLog(#"NEW VOL");
}
- (IBAction)AudioStopped:(id)sender {
NSLog(#"STOP");
}
- (IBAction)AudioPlayPaused:(id)sender {
NSLog(#"PLAY");
}
- (IBAction)TimeLabelPressed:(id)sender {
NSLog(#"TIMELABEL");
}
- (IBAction)CurrentPlayTimeChanged:(id)sender {
NSLog(#"NEW TIME POS");
}
#end
The .m method where the Subview is added:
- (void) addAudio_index:(int)index {
AudioPlayerViewController *audiov = [[AudioPlayerViewController alloc] init];
CGRect frame_s = [[[ScrollView subviews] objectAtIndex:[[ScrollView subviews] count]-1] frame];
CGRect frame = audiov.view.frame;
frame.origin.y = frame_s.size.height+frame_s.origin.y;
frame.origin.x = 0;
//[audiov.view setFrame:frame];
UIView *n =[[UIView alloc]initWithFrame:frame];
[ScrollView addSubview:n];
[n addSubview:audiov.view];
[audiov.view setHidden:FALSE];
}
The Player XIB:
I thought some hours about but I got no idea about any solution, so maybe you can help me...
Your code is retaining the AudioPlayerViewControllers view (and therefore all of the subviews) but it isn't retaining the audiov instance. So, when any of the views fire their actions they are calling an instance that has been deallocated.
To resolve, create a property and store the audiov (so that it is retained).
I have this header:
#interface MyBusinessesController : UIViewController
#property (weak, nonatomic) IBOutlet UITableView *businessList;
#property (weak, nonatomic) IBOutlet UILabel *loadingLabel;
#end
and I have this in my .m file:
#import "MyBusinessesController.h"
#interface MyBusinessesController ()
#end
#implementation MyBusinessesController
#synthesize businessList;
#synthesize loadingLabel;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(#"HIDING 1");
// HIDE THE LIST UNTIL IT LOADS
self.businessList.hidden=TRUE;
NSLog(#"HIDING 2");
}
- (void)viewDidUnload
{
[self setLoadingLabel:nil];
[self setBusinessList:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
When this controller runs, both of the NSLOG lines execute, and the exception happens after that.
Here is the exception:
-[MyBusinessesController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6a8f330
2012-07-29 21:31:38.355 BusinessPlan[3973:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyBusinessesController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6a8f330'
*** First throw call stack:
(0x13d5022 0x1566cd6 0x13d6cbd 0x133bed0 0x133bcb2 0x1fd06b 0x1ff862 0xad66d 0xad167 0xb0134 0xb4623 0x5dd42 0x13d6e42 0x1d8d679 0x1d97579 0x1d1c4f7 0x1d1e3f6 0x1d1dad0 0x13a999e 0x1340640 0x130c4c6 0x130bd84 0x130bc9b 0x12be7d8 0x12be88a 0x1f626 0x1bfd 0x1b65)
Would anyone be able to help me understand what is going wrong here?
Thanks!
You've probably set up the MyBussinessViewController as the datasource in interface builder but you didn't set up the datasource methods in it. You can check by right clicking on the tableview in interface builder and seeing what the datasource field is connected to.
For reference you need:
tableView:numberOfRowsInSection:
numberOfSectionsInTableView:
tableView:cellForRowAtIndexPath:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html
Happy coding.