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.
Related
I have a viewcontroller that has a uitableview being populated by my core data model. I am trying to set this up so I can tap on an item in the uitableview, have that item pass to a uitextfield on a second viewcontroller, where it can be edited and then saved back to my core data model.
prepare for segue
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"EditItemSegue"])
{
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
Item *item = [[self fetchedResultsController]objectAtIndexPath:indexPath];
[segue.destinationViewController setItemname:[item valueForKey:#"itemname"]];
}
}
error
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[EditItem setItemname:]: unrecognized selector sent to instance
Im pretty sure the error indicates that i am trying to perform an action on an object that isnt allowed.
Some help . push in the right direction would be appreciated.
edititem.h
#import "ViewController.h"
#interface EditItem : ViewController
#property (strong, nonatomic) IBOutlet UITextField *editItemField;
#property (nonatomic, strong) NSString *toDoItemName;
#end
edititem.m
#import "EditItem.h"
#interface EditItem ()
#end
#implementation EditItem
#synthesize editItemField;
#synthesize toDoItemName;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
editItemField.text = toDoItemName;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
edit
This is what I tried in my viewWillLoad
- (void)viewWillAppear:(BOOL)animated
{
[editItemField setText:toDoItemName];
}
You're calling setItemname: when you should be calling setToDoItemName:.
I am getting an error that I can't seem to solve:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[UICollectionViewController setSearchString:]: unrecognized
selector sent to instance 0x7fcd4b655930'
The error comes when I call a prepareForSegue method:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSString *searchStringToPass = [[NSString alloc]initWithFormat:_inputField.text];
UINavigationController *navController = [segue destinationViewController];
ResultsCollectionViewController *rvc = (ResultsCollectionViewController *)([navController viewControllers][0]);
NSLog(#"Search String to Pass is: %#", searchStringToPass);
//[rvc setSearchString:searchStringToPass];
rvc.searchString = searchStringToPass;
//userViewController.user = [self.users objectInListAtIndex:[self.tableView indexPathForSelectedRow].row];
}
The ViewController that I am trying to get to is imbedded in a navigation controller. The code for it is:
#import "ResultsCollectionViewController.h"
#interface ResultsCollectionViewController ()
//#property(nonatomic, weak) IBOutlet UICollectionView *collectionView;
#property(strong, nonatomic) NSArray *flickrPhotos;
#end
#implementation ResultsCollectionViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(#"search string is %#",_searchString);
}
-(void)getFlickrPhotosWithSearchString:(NSString*)searchString{
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
And the .h file is:
#import "BaseViewController.h"
#interface ResultsCollectionViewController : BaseViewController <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
#property (strong, nonatomic) NSString *searchString;
#end
Anybody have any idea what the issue is? Many thanks in advance.
You report the following error message:
-[UICollectionViewController setSearchString:]: unrecognized selector sent to instance 0x7fcd4b655930
Note that the "unrecognized selector" in the error message is the setter accessor method for your searchString property, but the class referenced is the standard UICollectionVieController, not your custom class.
That suggests that you neglected to specify the base class for the destination scene in Interface Builder. The storyboard has therefore instantiated a standard UICollectionViewController rather than your custom class, and thus your searchString accessor methods are not found.
This is extremely odd! Its simple stuff which is why i cannot understand. Below shows my class.
#import <UIKit/UIKit.h>
#interface LogInViewController : UIViewController
- (IBAction)loginButtonPressed:(id)sender;
#end
.
#import "LogInViewController.h"
#interface LogInViewController ()
#end
#implementation LogInViewController
- (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 from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//
- (IBAction)loginButtonPressed:(id)sender
{
NSLog(#"login Button Pressed");
}
Whenever i click the button though it throws this?!
loginButtonPressed:]: unrecognized selector sent to instance
0x15e3bf60 2013-10-28 11:23:24.249 Headache Mbl[1352:60b] *
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[__NSSetM
loginButtonPressed:]: unrecognized selector sent to instance
0x15e3bf60'
* First throw call stack:
Ive checked and the button is correctly sending the "touch up inside to loginButtonPressed:"
Help!, Thankyou:)
Here is how i attach the view controller to my main screen
import
#interface ViewController : UIViewController
#property (strong) IBOutlet UIView *loginView;
.
- (void)viewDidLoad
{
LogInViewController *logIn = [[LogInViewController alloc] initWithNibName:#"LogInViewController" bundle:nil];
[self.loginView addSubview:logIn.view];
[self.loginView setClipsToBounds:YES];
}
Looks like memory issues. If you are using ARC you should keep strong reference to view controller. If you are using manual memory management probably view controller has been overreleased. To find issues you can add NSZombieEnabled flag to scheme or use Instruments with Zombie.
Just a proposal, but did you check the event connections of the button in IB. May you left connection to another VC in which you've deleted the action method. Check in the console
loginButtonPressed:]: unrecognized selector sent to instance 0x15e3bf60
what is 0x15e3bf60 (po 0x15e3bf60).
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 am having trouble using some UIButtons to call actions in my Tab Bar application.
My .h file:
#import <UIKit/UIKit.h>
#interface ContactViewController : UIViewController {
UIButton *callTollFreeButton;
UIButton *callLocalButton;
UIButton *emailButton;
}
#property (nonatomic, retain) IBOutlet UIButton *callTollFreeButton;
#property (nonatomic, retain) IBOutlet UIButton *callLocalButton;
#property (nonatomic, retain) IBOutlet UIButton *emailButton;
-(IBAction)callPhone:(id)sender;
-(IBAction)callTollFree:(id)sender;
-(IBAction)clickEmailButton:(id)sender;
#end
My .m file:
#import "ContactViewController.h"
#implementation ContactViewController
#synthesize callLocalButton,callTollFreeButton,emailButton;
-(IBAction)callPhone:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:7576236600"]];
}
-(IBAction)callTollFree:(id)sender{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:8003334645"]];
}
-(IBAction)clickEmailButton:(id)sender{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"mailto:email#email.com?subject=Hello"]];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[callLocalButton release];
[callTollFreeButton release];
[emailButton release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[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 from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
My .m file:
The error message I get is (I get error message for any button clicked, this one is clicking the e-mail button in particular):
2011-11-19 18:39:38.786 Miller Tab Bar[761:207] -[UIViewController clickEmailButton:]: unrecognized selector sent to instance 0x6b29f40
2011-11-19 18:39:38.790 Miller Tab Bar[761:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController clickEmailButton:]: unrecognized selector sent to instance 0x6b29f40'
I've tried to connect and reconnect the outlets and actions to the objects on the view controller. Is it possible that it crashes because the SDK can't run test phone calls or e-mails?
I typed 'po 0x6b328d0' into the debugger to find out what the problem object is and it came back as a UIViewController which possibly means that the View Controller is being released before the action is called? What would be causing that?
Thanks.
In your Nib or storyboard, it looks like your view controller instance is of type UIViewController instead of ContactViewController.
So select the view controller in your Nib (or storyboard), and change its type to ContactViewController.
Of course, if this view controller isn't being loaded from a nib or storyboard, then just check where you create it and make sure you created an instance of the correct class.
It is a bit bizarre. I think your viewcontroller isn't being set up properly.
The bizarre part is you shouldn't be able to set the actions if it is not set up properly (File Owner- ContactViewController)
When I send an unrecognized selector to a custom ViewController, it says
-[customViewController foo]: unrecognized selector sent to instance 0x6a2b440
It seems the xib's actual file owner is being instantiated as a UIViewController
Try changing:
UIButton *callTollFreeButton;
UIButton *callLocalButton;
UIButton *emailButton;
to
IBOutlet UIButton *callTollFreeButton;
IBOutlet UIButton *callLocalButton;
IBOutlet UIButton *emailButton;
And hook up the UILabels to their respective buttons. See if that helps.