I've got a View Controller with five buttons. Each button should trigger a modal segue to a different view controller based on the tag of the button, represented by declared constants:
- (IBAction)aButtonTapped:(UIButton *)sender
{
[self buttonForSegue:sender];
}
-(void) buttonForSegue:(UIButton *)sender
{
switch ([sender tag])
{
case aVsAButton_tag:
[self performSegueWithIdentifier:#"aVsAModal" sender:self];
break;
case cVsCButton_tag:
[self performSegueWithIdentifier:#"cVsCModal" sender:self];
break;
case actVsAllButton_tag:
[self performSegueWithIdentifier:#"actVsAllModal" sender:self];
break;
case catVsAllButton_tag:
[self performSegueWithIdentifier:#"catVsAllModal" sender:self];
break;
case customDatePickerButton_tag:
[self performSegueWithIdentifier:#"customDatePickerModal" sender:self];
break;
default:
break;
}
}
Regardless of which button I hit, the app crashes in the sim with this message (only the button names change):
2014-02-10 19:11:47.305 WMDGx[24366:a0b] -[ReportViewController aVsAllButton:]: unrecognized selector sent to instance 0x8a911e0
2014-02-10 19:11:47.307 WMDGx[24366:a0b] * ** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ReportViewController aVsAllButton:]: unrecognized selector sent to instance 0x8a911e0'
My code looks reasonable to me, but apparently not. Can someone please tell me where I'm going wrong?
Thanks!
The error you're reporting would not be caused by the code you posted. I'm guessing that you have an IBAction link in your buttons and that action method no longer exists. Open your storyboard file, select the scene for your view controller, and use the connections inspector to check the action link for each button. You may need to break the connection and re-link it to the proper IBAction.
Looks like this has nothing to do with your switch statement, but rather calling a function that doesn't exist on one of your controllers.
Which line of code does it fail on? Entering the buttonForSegue? At the start of the switch? during one of the performSegueWithIdentifier?
Things you can try:
Ensure that sender is actually a UIButton class
Ensure that the tag is set on the button
Check the view controller that you are seguing to implements the method aVsAllButton
Related
So here's the case:
I wish to fill the prototype cells with the names of the friends selected in the UIPickerView over there. I have programatically filled the picker with the correct data, and set its properties using the delegate functions.
The "New Game Friends View" you see here has its own viewcontroller subclass, as has the table view, which I attempt to embed into a UIView on the "New Game Friends View".
I have in many ways tried to add data to the prototype cells, but with no luck. Here's my current addBtnClicked function:
- (IBAction)addBtnClicked:(id)sender {
WHGFriendTableViewController* tabView = (WHGFriendTableViewController*) [[self childViewControllers] objectAtIndex:0];
NSInteger row = [friendPicker selectedRowInComponent:0];
[[tabView selectedFriends] addObject:[[self friendList] objectAtIndex:row]];
}
This pretty much crashes my app. Whenever I hit the Add Friend button, the iPhone sends an abort signal, and gives back this message:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController
selectedFriends]: unrecognized selector sent to instance 0x978d530'
Any help with this problem is very appreciated. Thanks in advance!
Do you have a property called selectedFriends on your New Friends view controller?
If the answer is yes try:
- (IBAction)addBtnClicked:(id)sender {
WHGFriendTableViewController* tabView = (WHGFriendTableViewController*) [[self childViewControllers] objectAtIndex:0];
NSInteger row = [friendPicker selectedRowInComponent:0];
[[self selectedFriends] addObject:[[self friendList] objectAtIndex:row]];
}
If selectedFriends is a property of WHGFriendTableViewController, you should create a public method that adds a friend to the Mutable Array and call it from addBtnClicked IBAction.
I'm developing an iPad app to help me to manage my expenses when I'm abroad.
I have a split view with the classical master and detail views. In the master there is the list of the expenses and in the detail view, guess what? The details of every expense!
When I tap on a button in the detail a new view is loaded using a modal segue with a Form Sheet. The user insert a number and if that number is bigger than a certain value the colors of the labels in the master and in the detail will change.
When I save this number I dismiss the modal view and send a NSMessage to the master in order to reload the table with the new label colors and reload the detail view selected previously.
Everything work using the iOS Simulator, but when I run the app on my iPad (iPad 2), everything freeze and I got this message:
2013-11-09 21:52:04.763 IOUinTravel[562:60b] -[NSConcreteMapTable
backdropView:willChangeToGraphicsQuality:]: unrecognized selector sent
to instance 0x18b8fb00 2013-11-09 21:52:04.767 IOUinTravel[562:60b]
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMapTable
backdropView:willChangeToGraphicsQuality:]: unrecognized selector sent
to instance 0x18b8fb00'
* First throw call stack: (0x2df5bf4b 0x387386af 0x2df5f8e7 0x2df5e1cb 0x2dead4d8 0x30c88b43 0x306cd7b5 0x306cd6e5 0x306cd7d5
0x306cd6e5 0x306da5c3 0x306da417 0x30785f67 0x30785d83 0x3077de85
0x3077d30d 0x3077d07d 0x3077d015 0x306ceda3 0x30355c6b 0x3035147b
0x3035130d 0x30350d1f 0x30350b2f 0x306c70c3 0x2df271cd 0x2df24b71
0x2df24eb3 0x2de8fc27 0x2de8fa0b 0x32b70283 0x30733049 0x9a3d5
0x38c40ab7) libc++abi.dylib: terminating with uncaught exception of
type NSException (lldb)
I really do not know why and how to solve it.
The methods I've used are:
In the Form Sheet modal view:
- (IBAction)saveNumber:(id)sender {
// Do some stuff here
[self dismissViewControllerAnimated:YES completion:^{ [[NSNotificationCenter defaultCenter] postNotificationName:#"reloadAfterExpenseCheck" object:self];}];
}
In the main view:
- (void)reloadAfterExpenseCheck:(NSNotification *)notification
{
if ([[notification name] isEqualToString:#"reloadAfterExpenseCheck"]) {
NSLog(#"Messaggio ricevuto!");
NSLog(#"%#", self.indexPathToUpdate);
[self.tableView reloadData];
[self.tableView selectRowAtIndexPath:self.indexPathToUpdate animated:NO scrollPosition:UITableViewScrollPositionNone];
[self performSegueWithIdentifier:#"detailExpense" sender:self];
}
}
The segue #"detailExpense" works when I trigger it selecting a cell in the master table, so I do not know where is the problem... in the iOS sim it works!
Thank you for your answers.
I've solved this problem, I do not know it it is the best way but it works now.
I started to think that maybe there could be some asynchronous task going on. My Mac Mini cpu was fast enough to complete the first task, load the view and fill it with my data, the iPad cpu maybe was too slow so the view wasn't loaded... at least that is my guess.
I've simple added a NSTimer that fires the method used to load the detail view after a short time. The user do not notice the delay but it gives time to the iPad.
That's the code:
- (void)reloadAfterExpenseCheck:(NSNotification *)notification {
if ([[notification name] isEqualToString:#"reloadAfterExpenseCheck"]) {
[self.tableView reloadData];
[self.tableView selectRowAtIndexPath:self.indexPathToUpdate animated:NO scrollPosition:UITableViewScrollPositionNone];
//[self performSegueWithIdentifier:#"detailExpense" sender:self];
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:#selector(loadIt) userInfo:nil repeats:NO];
}
}
-(void)loadIt
{
[self performSegueWithIdentifier:#"detailExpense" sender:self];
}
I'm trying to create this application, when you press on a tablecell you get shown the ViewController, and the variable get's set in the other view controller. Although i'm getting a few errors when i press the uitablecell.
Error:
2013-04-06 22:47:25.970 iFSX Guide[1069:907] Called
2013-04-06 22:47:26.009 iFSX Guide[1069:907] -[__NSCFString _isAncestorOfFirstResponder]: unrecognized selector sent to instance 0x1d562390
2013-04-06 22:47:26.016 iFSX Guide[1069:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString _isAncestorOfFirstResponder]: unrecognized selector sent to instance 0x1d562390'
*** First throw call stack:
(0x319b22a3 0x3964c97f 0x319b5e07 0x319b4531 0x3190bf68 0x33832beb 0x338a837f 0x338548fb 0x33a95619 0x338a79b9 0x338a5fe7 0x339c83ef 0xa22a5 0x3387c28d 0x338fef81 0x322c0277 0x319875df 0x31987291 0x31985f01 0x318f8ebd 0x318f8d49 0x354ba2eb 0x3380e301 0xa19d1 0x39a83b20)
libc++abi.dylib: terminate called throwing an exception
The code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)in dexPath{
NSLog(#"Called");
Aircraft = indexPath.row;
[self performSegueWithIdentifier:#"ToSections" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"ToSections"]){
AirplaneSections *sections = (AirplaneSections *)segue.destinationViewController;
sections.plane = Aircraft;
}
}
I've found out that it's an error on ViewDidLoad on the viewcontroller.
NSString *quickTemp = [NSString alloc];
switch (plane) {
case 0:
quickTemp = #"Boeing 737-800";
break;
default:
break;
}
TitleLabel.text = quickTemp;
*/
I'm doing something wrong there.
Are you using ARC? This sort of problem usually indicates there's a memory error somewhere. Basically, some code somewhere is trying to access an object that was already released. This makes everything go kaboom.
If you aren't using ARC, you should turn it on.
After that, the next thing you should do is run the static analyzer. Fix anything that comes up.
If that doesn't fix the problem, in Xcode, add a breakpoint that stops when an Objective-C exception is thrown. It should show you where exactly this problem is happening.
If that doesn't help, run your code under Instruments' and the Zombie tool. This will show you exactly where you tried to access memory that was already released.
I have a modal view controller that appears, checks a service on the Internet and then dismisses itself when done. The nib contains an activity indicator and a label to inform the user what is going on.
When the update is complete, the label changes to "Update Complete" and then dismisses the view controller. However, I want it to delay the dismiss for a couple of seconds to give the user a chance to see the text before it disappears. So I've done this:
#pragma mark - AssetLoaderServiceDelegate
- (void)assetLoaderServiceDidFinishLoading:(AssetLoaderService *)service
{
[self.spinner stopAnimating];
self.infoLabel.text = #"Update complete";
[self performSelector:#selector(dismissUpdater) withObject:nil afterDelay:2.0];
}
- (void)dismissUpdater
{
[self dismissModalViewControllerAnimated:YES];
}
But for some reason, the selector is never being called. I've tried running it in mode NSRunLoopCommonModes too, but that doesn't work either.
I must be doing something wrong, but I can't see what...
EDIT: The delegate callback is actually happening within an NSOperationQueue, which might mean it's not on the same thread when it sends the message back to the view controller? So I tried
[self performSelector:#selector(downloadQueueComplete) withObject:nil afterDelay:0.0 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]];
followed by
- (void)downloadQueueComplete
{
[delegate assetLoaderServiceDidFinishLoading:self];
}
But the performSelector doesn't seem to be working here either.
Following up your suggestion about the thread issue, would you try with:
[self performSelectorOnMainThread:#selector(downloadQueueComplete) withObject:nil waitUntilDone:YES]];
Sorted! In the AssetLoaderService, I had to perform selector on main thread:
[self performSelectorOnMainThread:#selector(downloadQueueComplete) withObject:nil waitUntilDone:YES];
After that, all the following calls were on the correct thread. :)
I have never had this problem before or heard of it happening. I am using a Master-Detail Application (splitview) for the ipad. I have a dynamic tableview for my MVC and am trying to transition each cell to a custom view controller.
Currently I only have two items in my table. When the program boots I can select either of them and it will transition to the correct view controller without any problems. But most of the time when I click on something a second time the program crashes. Sometimes it takes four or five clicks but it always eventually crashes.
Here is the code snippet:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *segueName = [self.tableObjects objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:segueName sender:self];
}
tableObjects is an NSArray that I use to create the table items. If I throw a print statement in before the segue call it does print the correct segue name.
The error is always being thrown on the actual performSegueWithIdentifier call. I checked it with the debugger. The exception I keep getting is: EXC_BAD_ACCESS.
Again both of the segues work initially so I do not think it is a problem with this. Does this method sometimes get called randomly? Is there a way to double check that the method call is safe? Do I need to override performSegueWithIdentifier and do something there?
I attempted to put it into a try catch:
#try {
[self performSegueWithIdentifier:segueName sender:self];
}
#catch (NSException *exception) {
NSLog(#"%#", exception);
}
#finally {
NSLog(#"finally");
}
and it still pointed to the method call inside of the #try. It does not seem to be throwing the error like an exception?
FYI, I was running into this exact same issue, and I found the answer on another SO thread: iOS - UISplitViewController with storyboard - multiple master views and multiple detail views
Basically, the uisplitviewcontroller delegate needed to be set again when making the segue. Hope this helps someone in the future.