dismissModalViewControllerAnimated makes my app crash :( - iphone

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.

Related

UIImageview set image crash

I'm setting image to a UIImageView using in the below code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
for(int i=0;i<[radioButtons count];i++){
[[radioButtons objectAtIndex:i] setImage:[UIImage imageNamed:#"checkbox_unchecked.png"]];
}
UIImageView *imageViews=(UIImageView *)[self.view viewWithTag:indexPath.row];
[imageViews setImage:[UIImage imageNamed:#"checkbox_checked.png"]];
}
So on clicking any tableview cell the images gets sets. But once if I click on objectatindex:0
then the app crashes. I'm unable to fix this.
Below is the crash log:
2012-08-20 16:25:36.321 EventApp[2422:12503] -[UIView setImage:]: unrecognized selector sent to instance 0x79642b0
2012-08-20 16:25:36.321 EventApp[2422:12503] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setImage:]: unrecognized selector sent to instance 0x79642b0'
*** First throw call stack:
(0x1de3022 0x1c03cd6 0x1de4cbd 0x1d49ed0 0x1d49cb2 0x7a98c 0xc615c5 0xc617fa 0x14f685d 0x1db7936 0x1db73d7 0x1d1a790 0x1d19d84 0x1d19c9b 0x1be57d8 0x1be588a 0xbd0626 0x380a2 0x23b5)
terminate called throwing an exception(lldb)
I think you are not getting UIImageView Object,you are getting uiview types object that's why it crashes. you should try to Define another tag property like 999+indexPath.row. Got it somewhere you define the tag=0 or IB automatically takes tag=0 to all object so it taking uiview with tag 0 not uiimageView
this means that you are sending message -(void)setImage to UIView, not to UIImageView. Make sure that view with tag indexPath.row and all radioButtons in array are actually UIImageView

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.

scrollToRowAtIndexPath checks for indexpath before my tableview is set up

I am using the scrollToRowAtIndexPath to center my tableview on the previously selected cell, however its crashing the app while testing on the phone but not on the emulator.
This is how I set it up
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
//Center previously selected cell to center of the screen
[self.tableView reloadData];
[self.tableView scrollToRowAtIndexPath:oldCheckedIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
}
And this is the error its giving
*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]: section (0) beyond bounds (0).'
*** First throw call stack:
(0x31fe88bf 0x31d581e5 0x31fe87b9 0x31fe87db 0x32b6df1f 0x29bef 0x32ae26b5 0x32b3daf1 0x32afed21 0x32afea71 0x32afe78b 0x32afe4ff 0x32ab581b 0x32abafb9 0x3193aba7 0x3273be8d 0x31fbb2dd 0x31f3e4dd 0x31f3e3a5 0x3204afed 0x32ace743 0x34f5 0x2f70)
terminate called throwing an exception(gdb)
The thing being is I set
[self.tableView reloadData];
[self.tableView scrollToRowAtIndexPath:oldCheckedIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
in a different method the application works fine but dose not scroll to the index position..
I dont know how to fix it.
UPdate New error when trying to delay scrollToRowAtIndexPath
2011-11-02 16:00:58.180 code[2303:707] -[VehicleResultViewController methodThatCallsScrollToRow]: unrecognized selector sent to instance 0x1f3410
2011-11-02 16:00:58.184 code[2303:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[VehicleResultViewController methodThatCallsScrollToRow]: unrecognized selector sent to instance 0x1f3410'
*** First throw call stack:
(0x31fe88bf 0x31d581e5 0x31febacb 0x31fea945 0x31f45680 0x35bef943 0x31fbca63 0x31fbc6c9 0x31fbb29f 0x31f3e4dd 0x31f3e3a5 0x3204afed 0x32ace743 0x34a9 0x2f24)
terminate called throwing an exception(gdb)
You probably don't need to reload data - just run your scrollToRowAtIndexPath after a delay:
[self performSelector:#selector(methodThatCallsScrollToRow) withObject:nil afterDelay:2.5];
Give the table a chance to load.

IBAction being called NSCFDictionary and crashing app

I have an NSObject set up to control various elements on my screen.
I initialize the class inside my View Controller like this:
self.pageSetupClass = [[PageSetup alloc] set:self.pageID];
In IB I have added my NSObject object and linked a button to an IBOutlet on it. I've also linked it to an IBAction found in the object. When I click this button the app crashes and I get this error:
2010-09-23 15:33:11.640 BookTest10[49139:207] *** -[NSCFDictionary clickSoundByte:]: unrecognized selector sent to instance 0x4b10bc0
2010-09-23 15:33:11.641 BookTest10[49139:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFDictionary clickSoundByte:]: unrecognized selector sent to instance 0x4b10bc0'
2010-09-23 15:33:11.642 BookTest10[49139:207] Stack: (
42195024,
43352876,
42203739,
41666166,
41662962,
2915566,
3413054,
3422400,
3417197,
3042792,
2934339,
2965976,
51188092,
41474204,
41470120,
51181725,
51181922,
2958194
)
terminate called after throwing an instance of 'NSException'
There is nothing in the function at the moment so it must be the calling that crashes it...right?
If you need me to post more code I certainly can. If you have any ideas I'm all ears. Thank You
Edit:
This is the contents of the function set called out when I initialize the PageSetup object:
-(PageSetup*) set:(int) i {
self = [super init];
if(self) {
self.iD=i;
self.pageSetupFile = [[NSBundle mainBundle] pathForResource:#"PageSetup" ofType:#"plist"];
self.pageSetupArray = [[NSMutableArray alloc] initWithContentsOfFile:self.pageSetupFile];
self.pageInfo = [self.pageSetupArray objectAtIndex:self.iD];
[self initializeSoundBytes];
[self initializeAnimations];
[self initializeToys];
NSLog(#"Page Setup Initializing: %#", self.pageInfo);
return self;
}
return self;
}
Another Edit:
I set my set function to return (void) and no longer initialize it using init.
I now receive this error message:
2010-09-23 17:10:05.096 BookTest10[50519:207] *** -[UITouch clickSoundByte:]: unrecognized selector sent to instance 0x4b1b580
2010-09-23 17:10:05.097 BookTest10[50519:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UITouch clickSoundByte:]: unrecognized selector sent to instance 0x4b1b580'
2010-09-23 17:10:05.099 BookTest10[50519:207] Stack: (
42166352,
43324204,
42175067,
41637494,
41634290,
2886894,
3384382,
3393728,
3388525,
3014120,
2905667,
2937304,
51159420,
41445532,
41441448,
51153053,
51153250,
2929522
)
terminate called after throwing an instance of 'NSException'
Final Edit:
I had forgotten to connect my NSObject to the File's Owner in IB.
Could it be that when I reinitialize
this object...
Wait... what? In Objective-C you never call init* methods more than once.
In any case, the underlying problem appears to be a straightforward memory management issue. Something is being released before its time and it just so happens that a dictionary lands at that location. Turn on zombie detection and it'll likely catch the problem.
self.pageSetupClass = [[PageSetup alloc] set:self.pageID];
What does set: return? Is that a method of your PageSetup class? Does it return self?
Because apparently you're assigning pageSetupClass to whatever set: returns...
Unless set: returns self, you should try this:
self.pageSetupClass = [[PageSetup alloc] init];
[self.pageSetupClass set:self.pageID];
Edit:
ok, if you added the object in IB, the object was already instantiated for you when you loaded the nib, and the IBAction and IBOutlet connections have already been made.
When you do self.pageSetupClass = ..., you're setting pageSetupClass to a new instance, and that probably leaves the button with a bad target for its IBAction.
If the object was instantiated from the nib, and you have a reference to it in pageSetupClass from a IBOutlet, then just set whatever you want in the object, no need to alloc a new one.

how to solve unrecognized selector sent to instance?

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