ios - ECSlidingViewController "reason: '*** -[__NSArrayM insertObject:atIndex:]" - iphone

I'm using the following pages
-MenuViewController
-ViewController(Main)
-ListViewController
ECSlidingViewController created using the menu. ViewController (main) menu on page directly open, but when I try to open a subpage menu with the following line of listviewcontroller get the error:
[self.view addGestureRecognizer:self.slidingViewController.panGesture];
I received the error are as follows:
-[__NSArrayM insertObject:atIndex:]: object cannot be nil'

The NSArray method insertObject:atIndex does not accept nil. If you do want to insert a nil object into an array, or rather, a representation of a nil entry, use [NSNull null], so you have:
[myArray insertObject[NSNull null] atIndex:myIndex]
In your case, however, probably the root cause of the error is that self.slidingViewController.panGesture is nil.

I got this issue too. I issue was that when I added the ECSlidingViewController. I still had one of my functions connecting to the topviewcontroller
[[UIApplication sharedApplication].keyWindow setRootViewController: topViewController];
When I needed to make sure it was connected to the initial view controller for the ECSlidingViewController.
[[UIApplication sharedApplication].keyWindow setRootViewController: initialEXViewController];

Related

Changing Root View Controller to Tab View Controller in core data app (Xcode4)

I'm new to making core data iPhone apps. I created a new core data project in Xcode and attempted to add a tab Bar controller as the root view controller then putting the default tableview controller after the navigation controller in this hierarchy:
->Tab Bar Controller -> Navigation Controller -> TableView Controller -> TableView Controller2 ->details controller
I have implemented an app using navigation and tab bar controllers at the same time before, however for this app I need access to managedObjectModel throughout the app.
I have tried messing around with the app delegate such as didFinishLaunchingWithOptions etc.
I'm always getting messages similar to '
'Terminating app due to uncaught exception
'NSInvalidArgumentException',
reason: '-[UITabBarController
topViewController]: unrecognized selector sent to instance'
This is the code I am using to access the ManagedObjectContext:
AppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *newCoffee;
newCoffee = [NSEntityDescription
insertNewObjectForEntityForName:#"Coffee"
inManagedObjectContext:context];
And I'm getting this error:
No visible #interface for 'AppDelegate' declares the selector 'managedObjectContext'
I just noticed Xcode says its an ARC issue, how do I access mod with ARC enabled?
Well if I understand your question correct, you want to get access to you NSManagedObjectModel, so you can get acces to your stored data. Am I right?
Well first of all, you should import your Appdelegate in the viewController, where you need to save or load data.
Second of all, you should implement this in your viewDidLoad:
self.context = [self context];
if (self.context == nil)
{
self.context = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
}
with #property (nonatomic, retain) NSManagedObjectContext *context, in the headerfile.
I suggest you pass managed object context from controller to controller. Also if you're initializing some view controller with managed object, you can access MOC via managedObjectContext property of that object.
When saying Managed Object Model you mean Managed Object Context - right?
In both cases: You can access the context and the model at any time via the delegate of the shared application object like so:
[(YourAppDelegateClass *)[UIApplication sharedApplication] managedObjectContext]
But you can also just make a property for each view controller and pass the context down the hierarchy.

application crashing on ipod touch but not on iphone emulator

I followed the apple tutorial "Your First iOS Application" step by step and it works perfectly on the iPhone emulator.
But when I attempt to deploy it on an ipod touch, the application crashes.
here is the problematic method :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
MyViewController *acontroller = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:[NSBundle mainBundle]];
[self setMyViewController:acontroller];
[[self window] setRootViewController:[self myViewController]]; // crash here
[self.window makeKeyAndVisible];
[acontroller release];
return YES;
}
And here is the error message :
011-04-13 18:07:53.730 ios_HelloWorld[865:207] *** -[UIWindow setRootViewController:]: unrecognized selector sent to instance 0x119520
2011-04-13 18:07:53.754 ios_HelloWorld[865:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIWindow setRootViewController:]: unrecognized selector sent to instance 0x119520'
2011-04-13 18:07:53.770 ios_HelloWorld[865:207] Stack: (
843631901,
849079828,
843635709,
843131673,
843094080,
11801,
857435720,
857434728,
857767424,
857765436,
857763988,
875472868,
843380011,
843377695,
857431048,
857424432,
11553,
11476
)
terminate called after throwing an instance of 'NSException'
Consider that I have followed the tutorial step by step (and re-did it by my own) and it always crashes at this spot.
Any idea?
thanks
KiTe
self.window.rootViewController vs window addSubview
Have a look at the documentation, the desired property is not available on that iOS Version. You will have to update or build in some conditional workaround.
rootViewController The root view
controller for the window.
#property(nonatomic,retain)
UIViewController *rootViewController
Discussion The root view controller
provides the content view of the
window. Assigning a view controller to
this property (either programmatically
or using Interface Builder) installs
the view controller’s view as the
content view of the window. If the
window has an existing view hierarchy,
the old views are removed before the
new ones are installed.
The default value of this property is
nil.
Availability Available in iOS 4.0 and
later.
The setRootViewController method is only available in iOS 4.0 and above.

Crash (SIGABRT) while adding a view. (WebView)

I am having a crash (triggered by an exception) while adding a WebView. I haven't figured out why. And yes I have browsed the web because this is a very common problem though with no success, I found an answer saying that I should implement the DSYM to track the stack correctly, because looking at all those addresses is just meaningless (and I agree), the thing is I have no idea on how to do this. I found this: save dsym files. But I didn't figure out how to integrate it into my project, besides it looks dangerous. And yes I have NSZombie enabled too, but to no avail.
Anyway now to the point of my question. I have a button that triggers an event, the event changes a string (the URL) according to the button pressed. Then this IBAction calls on the delegate, and the delegate makes a transition to a view that has a UIWebView that will open with the URL edited by the IBAction. So I have the following code:
This is the Delegate method:
WebViewController *awebViewController = [[WebViewController alloc]
initWithNibName:#"WebView" bundle:nil];
[self setWebViewController:awebViewController];
[awebViewController release];
self.webViewController.finalURL = [NSMutableString stringWithFormat:#"%#", linkString];
[viewController.view removeFromSuperview];
// HERE happens the crash, found out using breakpoints
[self.window addSubview:[webViewController view]];
[UIView commitAnimations];
[viewController release];
viewController = nil;
This is the exact crash message:
-[WebView initWithCoder:]: unrecognized selector sent to instance 0x5718320
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '[WebView initWithCoder:]: unrecognized selector sent to instance 0x5718320'
I have the theory that it tries to make the transition but that there is no actual view to add. Though that is a wild guess. Exceptions are usually called by those kinds of things but in this case I don't see what is happening.
Thank you for your help, and forgive me if it is too dumb a question.
a guess from my side:
Do you have a view in your nib that should be a UIWebView but you changed the Class of that view to WebView?
You should first check this in interface builder.
This exception is exactly what happens if you change the Class of a view element to a class that isn't available.
The exact error is that some instance of a class called WebView (not UIWebView) at memory address 0x5718320 is being sent the message -initWithCoder:, which it doesn’t recognize. That message is called when loading views created with Interface Builder; check your nibs for a view that you’ve changed to a custom WebView class.
I had same problem, and renamed class WebView into WebViewCustom by XCode refractor/Rename feature, cleaned up project and now it works fine.

Crashing app when i want to go rootview from other view controller

I want to go Root view Controller from another view controller but i got the terminating error. following is the error message in console,
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray removeObjectsInRange:]: index (4) beyond bounds (1)'
This is my code for that
NSArray *arr=self.navigationController.viewControllers;
[self.navigationController popToViewController:[arr objectAtIndex:2] animated:YES];
So any one can give me the suggestion on it so can remove the crash
The NavigationController has a method called to pop to its root view controller. Maybe you should use this one instead.
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated

Why does rotation of iPhone cause crash when _existingView message is sent to deallocated object?

I have two view controllers: MyParentViewController and MyChildViewController.
The application starts with MyParent. I push the MyChild controller to the top of the navigation stack, so that the chain is like so:
MyParent > MyChild
I log the object ID of MyChild with NSLog(#"%p", self):
2009-11-20 05:08:29.305 MyApp[2213:207] MyChildViewController instance: 0x36afc20
When I press the back button from MyChild this pops MyChild off the stack and returns me to MyParent.
When I rotate the iPhone while viewing MyParent, my application crashes with the following error message:
2009-11-20 05:08:37.671 MyApp[2213:207] *** -[MyChildViewController _existingView]: message sent to deallocated instance 0x36afc20
I have no _existingView method or instance variable in MyChildViewController.
If I pop MyChild off the stack, I think the navigation controller will release it, and I presume that it would be set to nil, and that any messages sent to it would be ignored. Though that's not happening here, obviously.
Does anyone have any ideas why my application crashes on rotation?
Is there a way to find out what is sending the _existingView message to MyChild?
EDIT
Here's the code for pushing MyChild on the stack:
MyChildViewController *_myChildViewController = [[MyChildViewController alloc] initWithNibName:#"MyChildViewController" bundle:nil];
_myChildViewController.managedObjectContext = self.managedObjectContext;
_myChildViewController.title = [_xyz name];
[self.navigationController pushViewController:_myChildViewController animated:YES];
UIBarButtonItem *_backButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"MyChildViewBackBarButtonItemTitle", #"") style:UIBarButtonItemStyleDone target:nil action:nil];
self.navigationItem.backBarButtonItem = _backButton;
[_backButton release];
[_myChildViewController release];
EDIT 2
I think I may have solved this. I have an UISearchDisplayController added to the view controller nib via Interface Builder.
Originally, I set this to nil when the MyChild controller is sent -viewDidUnload, thinking it is usually enough to set IBOutlet instances to nil in this method. But this doesn't appear to be enough for my search display controller. When I release this in -dealloc I don't get the crash. Is this a bug, I wonder, or expected behavior?
There is a way to find out more about who called (found here):
[...] Also, by the time the app is
terminated due to the uncaught
exception there is no useful
backtrace. If you set a breakpoint on
objc_exception_throw the debugger will
break before the exception is thrown
and you'll have a useful backtrace. I
do this with a .gdbinit file. Create a
file named .gdbinit and place it in
your home directory. This is the
contents of mine:
fb -[NSException raise]
fb -[_NSZombie release]
fb szone_error
fb objc_exception_throw
It's also possible to set these kinds
of breakpoints in the Xcode
breakpoints window or in the debugger
console. [...]
But I assume that won't fix your problem... _existingView seems to be called by the framework when rotating the phone. The only line I can think of telling the framework to perform this on _myChildController is this one:
myChildViewController.managedObjectContext = self.managedObjectContext;
Doesn't it work without this?
_existingView is an internal variable of an UIViewController instance, defined in UIViewController.h
Maybe you are retaining your MyChildViewController someplace in your code.
I was struggling with this too, and the solution was similar to Alex Reynolds'. I release my UISearchDisplayController on -dealloc method, but it had to be before the [super dealloc]. If I release it after super deallocation, it still crashes.