how to solve unrecognized selector sent to instance? - iphone

I have a uitableview 'A' which has cells, on clicking one of the cell, it needs to push another table view 'B'. and now when a cell is clicked in 'B', its needs to open a simple view.
I have managed to display both the tables in two different views. but when a cell is clicked in the menu B. it hangs and shows the below message
> unrecognized selector sent to > instance
could someone please tell me how do i solve this.thanks
Please find below my code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
NSLog(#"entering the if loop libdecripviewcontoller");
if(self.libraryDescripViewController == nil){
NSLog(#"its creating new instance of libdecripviewcontoller");
LibraryDescripViewController *aLib = [[LibraryDescripViewController alloc] initWithNibName:#"LibraryDescripView" bundle:nil];
self.libraryDescripViewController = aLib;
[aLib release];
}
libraryDescripViewController.title = [NSString stringWithFormat:#"%#",[libraryMenu objectAtIndex:row]];
ULS1AppDelegate *delegate = [[UIApplication sharedApplication] delegate ];
[delegate.searchLibNavController pushViewController:libraryDescripViewController animated:YES];
}
Please find the output below
2010-06-27 20:13:15.521 ULS1[1020:207]
entering the if loop
libdecripviewcontoller 2010-06-27
20:13:15.533 ULS1[1020:207] its
creating new instance of
libdecripviewcontoller 2010-06-27
20:13:15.541 ULS1[1020:207] *
-[LibraryMenuTabViewController setLibraryDescripViewController:]:
unrecognized selector sent to instance
0x3c2ec70 2010-06-27 20:13:15.554
ULS1[1020:207] * Terminating app due
to uncaught exception
'NSInvalidArgumentException', reason:
'*** -[LibraryMenuTabViewController
setLibraryDescripViewController:]:
unrecognized selector sent to instance
0x3c2ec70' 2010-06-27 20:13:15.558
ULS1[1020:207] Stack: ( 29303899,
2512004361, 29685819, 29255286,
29107906, 14755, 3050054, 3033220,
287146, 29088448, 29084744, 37393941,
37394138, 2777007, 11184, 11038 )

You can get more information about where the error is happening by opening your debugger window, clicking on "Show Breakpoints", and setting the following two breakpoints:
[NSException raise]
objc_exception_throw
Now when your app is about to crash, the debugger will usually show you exactly what line of code is causing the problem.
For this reason, it's good practice to have these breakpoints on every app you are developing.

It seems that you are calling "self.libraryDescripViewController = aLib" which is another way of writing [self setLibraryDescripViewController:alib].
The most likely cause of this would be in that you haven't declared the method setLibraryDescripViewController in your class.
Hope this helps.

There is way too little information here to diagnose exactly whats causing this, but one thing is certain. The method you are sending to the object is not defined for that object. Please post the code thats causing the error and the .h and .m files for the simple view you are talking about.
You probably need to set the class of the view controller in IB to LibraryDescripViewController. Double click the LibraryDescripViewController.xib file in xcode and when IB opens, in the identity view of the file's owner set the class to LibraryDescripViewController

Related

Which class must I extend?

(I am developing an app that presents chat messages in a table. But, this chat can't be started by the user, when the user receives a message the chat view opens. So, I made this code:
- (void) newMessageReceived:(NSMutableDictionary *)message
{
General *general = [General sharedManager];
NSString *firstmessage=[message objectForKey:#"msg"];
NSString *from=[message objectForKey:#"sender"];
NSArray *listItems = [from componentsSeparatedByString:#"#"];
NSString *fromsplit=[listItems objectAtIndex:0];
general.firstmess=firstmessage;
general.firstfrom=fromsplit;
NSLog(#"Mensaje recibido: %# de %#", [message objectForKey:#"msg"], fromsplit);
ChatViewController *cvc=[[ChatViewController alloc]initWithNibName:#"Chat" bundle:nil];
[[self navigationController]pushViewController:cvc animated:YES];
}
Everything is ok, until here. The ChatViewController extends UITableViewController. But, when a message is received i get the following exception:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "Chat" nib but didn't get a UITableView.
Then, i try to change the class extended to UIViewController (did this to check that the program enters the numberOfRowsInSection method) and then i receive:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ChatViewController setTableViewStyle:]: unrecognized selector sent to instance 0x9863200'
I think that solving the first exception would fix my problem. Any help?
Thank you.
In the second exception i think you have called [self setTableViewStyle:] method, while
you have made it UIViewController.
So try to call this method by tableViewOutlet.
[tableView setTableViewStyle:];
Hope this will help you
Solved it. i click the .xib file, under "objects", clicked "View". And then, in the Identity Inspector (the third one, starting from the left), in Custom Class, set it to UITableView. It was simply "View" before. And then, everything worked fine.

App Crashing when returning from background

My application is crashing when it returns back from the background at certain places:
-[UITableViewCellContentView updateToInterfaceOrientation]: unrecognized selector sent to instance 0x165470
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCellContentView updateToInterfaceOrientation]: unrecognized selector sent to instance 0x165470'
The error is always similiar somtimes its with
[UIScrollViewDelayedTouchesBeganGestureRecognizer updateToInterfaceOrientation]
I'm really clueless as to why this is happening, any help would be much appreciated.
EDIT:
Ok, this is how I am creating my table view in the loadView method:
int tableCells = [formDS.tableItems count];
int tableHeight = FORM_TABLE_CELL_HEIGHT * (tableCells);
UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, yCoord, FORM_TABLE_WIDTH, tableHeight) style:UITableViewStyleGrouped];
[table setBackgroundView:nil];
table.backgroundView.backgroundColor = UIColorFromRGB(FORM_BODY_COLOR);
table.backgroundColor = UIColorFromRGB(FORM_BODY_COLOR);
table.dataSource = self;
table.delegate = self;
[localContainerView addSubview:table];
It looks like you have some released object and because of that some other objects now present at the same address in memory receive the call for updateToInterfaceOrientation.
Try hitting COMMAND + SHIFT + B (or go to Product -> Analyze in XCode's top bar menu) to have XCode make a static analyze of your code and get some hints of what might go wrong.
Hope that's going to help!

Simple functions giving me a crash on Objective-C

I'm coding a simple calculator and I want to make an unique function for all 4 arithmetic buttons. I got here:
-(IBAction)simbolo1:(UIButton*)sender{
if (isNumeric(campo1.text)) {
NSString *str=campo1.text;
campo2.text=str;
int S=1;
NSString *cmp1 = [NSString stringWithFormat:#"%d", S];
sinal.text=cmp1;
campo1.text=#"";
} else {
campo1.text=#"Only numeric values";
}
}
But, for some reason, I cant get this to work. Everytime I click in the button, I get a crash.
So, I check where really was the error and I deleted the whole code:
-(void)simbolo1:(UIButton*)sender{
campo1.text=#"Only numeric values";
}
Those lines of code appear to gave me the same error as before
I'm getting a 'green :marker' on this file:
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]){
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil); <--------- This line right here
[pool release];
return retVal;
}
EDIT---------------
On the debud console im getting this:
2011-09-30 09:17:14.319 Teste iPhone[28432:fb03] Applications are expected to have a root view controller at the end of application launch
2011-09-30 09:17:21.714 Teste iPhone[28432:fb03] -[Teste_iPhoneAppDelegate simbolo1]: unrecognized selector sent to instance 0x6b7c2d0
2011-09-30 09:17:21.715 Teste iPhone[28432:fb03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Teste_iPhoneAppDelegate simbolo1]: unrecognized selector sent to instance 0x6b7c2d0'
*** First throw call stack:
(0x166d062 0x17fed0a 0x166ecfd 0x15d3f10 0x15d3cf2 0x166eed9 0x16eb2 0x16e4a 0xbc3e6 0xbc8af 0xbbb6e 0x3c2a0 0x3c4c6 0x22c74 0x16399 0x1557fa9 0x16411d5 0x15a6042 0x15a492a 0x15a3dd4 0x15a3ceb 0x1556879 0x155693e 0x1438b 0x272d 0x26a5)
terminate called throwing an exception(gdb)
There is not enough information to help you. You need to look in the debugger console and show us the error and the stack.
However, I'm going to take a wild guess and say that you didn't connect the campo1 IBOutlet to its UIView in Interface Builder, and that it's nil. To fix, edit the view in Interface Builder (or in Xcode 4, just click on it), and drag the little circle next to the campo1 outlet (in the Connections tab) onto the UIView component that you want it to correspond to.
If that's not it, the error isn't here, but is probably caused by something else in your program.
[EDIT after seeing console]: Your connections look misconfigured. Why would it try to send the simbolo1 selector to Teste_iPhoneAppDelegate? It should send it to your ViewController. Did you play around with the connections (specifically, the delegate one) in Interface Builder -- or the class?
to set text in UITextField use
[campo1 setText:#"Only numeric values"];
and also don't forget to link IBOutlet UITextField* campo1; to proper UITextField in XCode IB

objective c : hand over delegate to other class

I am here confronted with a certain problem. I have a protocol which states a method, that returns the datasource for my tableviews. The datasources are generated by one class, for 3 tableviews. If you tap on one cell, you get to the next tableview with a different source and so on (I think you get the point).
Everything works fine for the first tableview, but as I hand over the deletage to the next tableview I still do not get the datasource for the second. Do I have to release the delegate at a certain point? And if I have to, how do I get it back, when the navigationbarbuttonitem is tapped on...?
Tell me if you have any ideas.
EDIT:
if ([Where isEqualToString:#"System"])
{
if ([exchangeDelegate respondsToSelector:#selector(getNewDataSourceForSystem:)])
{
[exchangeDelegate getNewDataSourceForSystem: [controlDelegate setBranchNavigation:What]];
}
}
else if ([Where isEqualToString:#"User"])
{
if ([exchangeDelegate respondsToSelector:#selector(getNewDataSourceForUser:)])
{
[exchangeDelegate getNewDataSourceForUser: [controlDelegate setLeafNavigation:What]];
}
}
if ([exchangeDelegate respondsToSelector:#selector(getNewDataSourceForCostumer:)])
{
[exchangeDelegate getNewDataSourceForCostumer: [controlDelegate setRootNavigation]];
}
each respondToSelector goes to a different class.
EDIT:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Costumers getNewDataSourceForSystem:]: unrecognized selector sent to instance 0x8a3b0e0'
Thats what I get as an exception when I leave out respondsToSelector:#selector.
Have you called -[UITableView reloadData] to inform it about invalidation of its current state?
And have you overloaded you delegate setter method in order to also fetch and set the new datasource and delegate as needed? Probably something like this:
-(void)setDelegate:(id<MYDelagate>)delegate;
{
myTableView.dataSource = [delegate tableViewDataSource];
myTableView.delegate = [delegate tableViewDelegate];
_delegate = delegate;
}
So, as it seems, using a singleton is the proper way to store my data for my views:
I created a singleton.
The singleton holds my 3 different data-arrays.
The delegate sends the new arrays to the singleton.
I am fetching the data from the views via the singleton.
As simple as it is ... thank you guys for your inspiration :-)

dismissModalViewControllerAnimated makes my app crash :(

I'm creating an iPad app, and I have two classes: NWRootViewController : UITableViewController and UINewFeedViewController : UIViewController. In NWRootViewController I have an UIBarButtonItem, which, when tapped, pops up a modal view controller called NWNewFeedViewController:
// THIS CODE IS IN NWROOTVIEWCONTROLLER.M
// New Feed
-(IBAction)showNewFeedViewAction:(id)sender {
[newFeedViewController setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentModalViewController:newFeedViewController animated:YES];
}
This works fine. However, in the NWNewFeedViewController's view, I have another UIBarButtonItem which does this when tapped:
// THIS CODE IS IN NWNEWFEEDCONTROLLER.M
// Buttons
-(IBAction)cancelAction:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
When I tap this button, the app crashes with:
2010-04-10 12:39:46.703 News[580:207] *** -[NWDetailViewController cancelAction:]: unrecognized selector sent to instance 0x4741110
2010-04-10 12:39:46.705 News[580:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NWDetailViewController cancelAction:]: unrecognized selector sent to instance 0x4741110'
2010-04-10 12:39:46.705 News[580:207] Stack: (
40878667,
2458187017,
41150267,
40613142,
40609810,
2776006,
4876265,
2776006,
3246293,
3255055,
3250242,
2899304,
2793965,
2825287,
49238396,
40419388,
40415304,
49232029,
49232226,
2817505
)
Can anyone help me? Thanks
Your cancel button has a target of your detail controller; you meant to target your new feed controller. So check how you configured the cancel button.
Your app is trying to call an object that has already been released. Enable zombie objects as explained here to find out what object is trying to be accessed.