I am creating my first iPhone app in which the first screen displays a table view the user selects from. It works before localization using the method below.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
navigationController = [[UINavigationController alloc] init];
[self.window addSubview:[self.navigationController view]];
if(self.selectCategoryViewController == nil)
{
SelectCategoryViewController *viewTwo = [[SelectCategoryViewController alloc] initWithNibName:#"SelectCategoryViewController" bundle:[NSBundle mainBundle]];
self.selectCategoryViewController = viewTwo;
[viewTwo release];
}
[self.navigationController setNavigationBarHidden:YES];//this will hide the navigation bar
[self.navigationController pushViewController:self.selectCategoryViewController animated:YES];
//self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
After I localized it by adding the Japanese localization file and changing the above to this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
navigationController = [[UINavigationController alloc] init];
[self.window addSubview:[self.navigationController view]];
if(self.selectCategoryViewController == nil)
{
NSBundle *myLocalizedBundle=[NSBundle bundleWithPath:[NSString stringWithFormat:[[NSBundle mainBundle]bundlePath],"en.lproj"]];
NSLog(#"the localized bundle is %#",myLocalizedBundle);
SelectCategoryViewController *viewTwo=[[SelectCategoryViewController alloc] initWithNibName:#"SelectCategoryViewController" bundle:myLocalizedBundle];
self.selectCategoryViewController = viewTwo;
[viewTwo release];
}
[self.navigationController setNavigationBarHidden:YES];//this will hide the navigation bar
[self.navigationController pushViewController:self.selectCategoryViewController animated:YES];
[self.window makeKeyAndVisible];
return YES;
}
it crashes with the following error:
√sh.app> (loaded)
2013-02-18 18:04:35.196 PictureEnglish[5529:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFString substringFromIndex:]: Range or index out of bounds'
*** Call stack at first throw:
(
0 CoreFoundation 0x012775a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x013cb313 objc_exception_throw + 44
2 CoreFoundation 0x0122fef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x0122fe6a +[NSException raise:format:] + 58
4 Foundation 0x00033086 -[NSString substringFromIndex:] + 133
5 PictureEnglish 0x00008524 -[SelectCategoryViewController viewDidLoad] + 937
6 UIKit 0x00378089 -[UIViewController view] + 179
7 UIKit 0x00376482 -[UIViewController contentScrollView] + 42
8 UIKit 0x00386f25 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48
9 UIKit 0x00385555 -[UINavigationController _layoutViewController:] + 43
10 UIKit 0x00386870 -[UINavigationController _startTransition:fromViewController:toViewController:] + 524
11 UIKit 0x0038132a -[UINavigationController _startDeferredTransitionIfNeeded] + 266
12 UIKit 0x0049c2e9 -[UILayoutContainerView layoutSubviews] + 226
13 QuartzCore 0x010a7a5a -[CALayer layoutSublayers] + 181
14 QuartzCore 0x010a9ddc CALayerLayoutIfNeeded + 220
15 QuartzCore 0x0104f0b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
16 QuartzCore 0x01050294 _ZN2CA11Transaction6commitEv + 292
17 UIKit 0x002ca9c9 -[UIApplication _reportAppLaunchFinished] + 39
18 UIKit 0x002cae83 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 690
19 UIKit 0x002d5617 -[UIApplication handleEvent:withNewEvent:] + 1533
20 UIKit 0x002cdabf -[UIApplication sendEvent:] + 71
21 UIKit 0x002d2f2e _UIApplicationHandleEvent + 7576
22 GraphicsServices 0x01bcf992 PurpleEventCallback + 1550
23 CoreFoundation 0x01258944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
24 CoreFoundation 0x011b8cf7 __CFRunLoopDoSource1 + 215
25 CoreFoundation 0x011b5f83 __CFRunLoopRun + 979
26 CoreFoundation 0x011b5840 CFRunLoopRunSpecific + 208
27 CoreFoundation 0x011b5761 CFRunLoopRunInMode + 97
28 UIKit 0x002ca7d2 -[UIApplication _run] + 623
29 UIKit 0x002d6c93 UIApplicationMain + 1160
30 PictureEnglish 0x00001cec main + 102
31 PictureEnglish 0x00001c7d start + 53
32 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Any suggestions on how I should call the SelectCategoryViewController for the selected language?
This line looks wrong to me:
NSBundle *myLocalizedBundle=[NSBundle bundleWithPath:[NSString stringWithFormat:[[NSBundle mainBundle]bundlePath],"en.lproj"]];
You probably meant something like this:
NSString* path= [[NSBundle mainBundle] pathForResource:#"en" ofType:#"lproj"];
NSBundle* bundle:myLocalizedBundle = [NSBundle bundleWithPath:path];
SelectCategoryViewController *viewTwo = [[SelectCategoryViewController alloc] initWithNibName:#"SelectCategoryViewController" bundle:myLocalizedBundle];
This is discussed more here: Manually loading a different localized nib in iOs
Note that this is only required if you want to do an in-app language selection. Localization should typically use the iOS device's selected language, in which case all this is much more straightforward (you simply let iOS pick the bundle for you).
xcode 5:
i had to clean build, clean build folder,delete derived data, reset simulator, close simulator, close Xcode.
Open project again and it's working.
Problem - This is a problem of project path, I think [self.window makeWindowKeyVisible] can not be able to find a path to your first assigned controller...
Solution - It happens some time, when your project suddenly stopped work, So no worries - just shift your project to other path, or just change the name of folder where actually your project resides and it will started working fine....
It works for me successfully...
Related
I have create a demo project in which i have add button. On button action i am calling a custom view. On that custom view i have add a picker view, a toolbar and bar button. On action of button i am calling that custom view. I have used this code...
-(IBAction)Picker{
mpv_object = [[MyPickerView alloc] initWithNibName:#"MyPickerView" bundle:nil];
[self.view addSubview:mpv_object];
[mpv_object release];
}
But i give error which i given below...
2011-09-26 09:49:00.236 Web[440:207] -[MyPickerView initWithNibName:bundle:]: unrecognized selector sent to instance 0x4b4dcb0
2011-09-26 09:49:00.287 Web[440:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyPickerView initWithNibName:bundle:]: unrecognized selector sent to instance 0x4b4dcb0'
* Call stack at first throw:
(
0 CoreFoundation 0x00daebe9 exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f035c2 objc_exception_throw + 47
2 CoreFoundation 0x00db06fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d20366 __forwarding + 966
4 CoreFoundation 0x00d1ff22 _CF_forwarding_prep_0 + 50
5 Web 0x0000223a -[WebViewController Picker] + 102
6 UIKit 0x002b7a6e -[UIApplication sendAction:to:from:forEvent:] + 119
7 UIKit 0x003461b5 -[UIControl sendAction:to:forEvent:] + 67
8 UIKit 0x00348647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
9 UIKit 0x003471f4 -[UIControl touchesEnded:withEvent:] + 458
10 UIKit 0x002dc0d1 -[UIWindow _sendTouchesForEvent:] + 567
11 UIKit 0x002bd37a -[UIApplication sendEvent:] + 447
12 UIKit 0x002c2732 _UIApplicationHandleEvent + 7576
13 GraphicsServices 0x016e4a36 PurpleEventCallback + 1550
14 CoreFoundation 0x00d90064 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52
15 CoreFoundation 0x00cf06f7 __CFRunLoopDoSource1 + 215
16 CoreFoundation 0x00ced983 __CFRunLoopRun + 979
17 CoreFoundation 0x00ced240 CFRunLoopRunSpecific + 208
18 CoreFoundation 0x00ced161 CFRunLoopRunInMode + 97
19 GraphicsServices 0x016e3268 GSEventRunModal + 217
20 GraphicsServices 0x016e332d GSEventRun + 115
21 UIKit 0x002c642e UIApplicationMain + 1160
22 Web 0x00001f80 main + 102
23 Web 0x00001f11 start + 53
)
terminate called after throwing an instance of 'NSException'
What is error in this?
It sounds like MyPickerView is a UIView subclass. initWithNibName:bundle is not a method that exists on UIView subclasses. It is a method that exists on UIViewController subclasses. That is what the error message means.
unrecognized selector sent to instance suggests that MyPickerView's superclass doesn't know what initWithNibName:bundle is, which is because UIView doesn't know that method (it exists in UIViewController).
Right way to do this would be something like this
UIView *dpView;
NSArray *nibViews;
nibViews = [[NSBundle mainBundle] loadNibNamed:#"DatePickerSliderViewNew" owner:self options:nil];
dpView = [ nibViews objectAtIndex: 0];
int outside = CGRectGetMaxY(self.view.bounds);
dpView.frame = CGRectMake(0, outside, 320, 260);
[self.view addSubview:dpView];
[UIView beginAnimations:nil context:nil];
dpView.frame = CGRectMake(0, outside - 260, 320, 260);
[UIView commitAnimations];
I have a TTSplitViewController in which I am trying to show a UITabBarController at the left pane, via the code:
#implementation SplitAppController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
[self setupURLRouting];
}
return self;
}
- (void)setupURLRouting {
[self routePrimaryNavigator];
[self routeDetailsNavigator];
}
- (void)routePrimaryNavigator {
TTURLMap* map = self.primaryNavigator.URLMap;
// Forward all unhandled URL actions to the right navigator.
[map from: #"*" toObject: self selector: #selector(willOpenUrlPath:)];
[map from:#"tt://primary" toViewController:[RootViewController class]];
}
RootViewController here is a UITabBarController. However, I am getting the following error:
2011-07-08 08:04:23.739 app[3241:207] -[RootViewController topViewController]: unrecognized selector sent to instance 0x520c060
2011-07-08 08:04:23.755 app[3241:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RootViewController topViewController]: unrecognized selector sent to instance 0x520c060'
*** Call stack at first throw:
(
0 CoreFoundation 0x017d95a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0192d313 objc_exception_throw + 44
2 CoreFoundation 0x017db0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0174a966 ___forwarding___ + 966
4 CoreFoundation 0x0174a522 _CF_forwarding_prep_0 + 50
5 app 0x000f73ff -[TTSplitViewController updateSplitViewButton] + 176
6 app 0x000f75d9 -[TTSplitViewController viewDidAppear:] + 90
7 UIKit 0x00ae1fab -[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] + 694
8 UIKit 0x00a64e4b -[UIView(Internal) _didMoveFromWindow:toWindow:] + 918
9 UIKit 0x00a63a60 -[UIView(Hierarchy) _postMovedFromSuperview:] + 166
10 UIKit 0x00a5c750 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1080
11 UIKit 0x00a5aaa3 -[UIView(Hierarchy) addSubview:] + 57
12 app 0x00083d01 -[TTBaseNavigator setRootViewController:] + 306
13 app 0x000841f9 -[TTBaseNavigator presentController:parentController:mode:action:] + 70
14 app 0x00084437 -[TTBaseNavigator presentController:parentURLPath:withPattern:action:] + 359
15 app 0x00084975 -[TTBaseNavigator openURLAction:] + 1320
16 app 0x0000c440 -[appAppDelegate application:didFinishLaunchingWithOptions:] + 848
17 UIKit 0x00a2bc89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
18 UIKit 0x00a2dd88 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
19 UIKit 0x00a38617 -[UIApplication handleEvent:withNewEvent:] + 1533
20 UIKit 0x00a30abf -[UIApplication sendEvent:] + 71
21 UIKit 0x00a35f2e _UIApplicationHandleEvent + 7576
22 GraphicsServices 0x01fee992 PurpleEventCallback + 1550
23 CoreFoundation 0x017ba944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
24 CoreFoundation 0x0171acf7 __CFRunLoopDoSource1 + 215
25 CoreFoundation 0x01717f83 __CFRunLoopRun + 979
26 CoreFoundation 0x01717840 CFRunLoopRunSpecific + 208
27 CoreFoundation 0x01717761 CFRunLoopRunInMode + 97
28 UIKit 0x00a2d7d2 -[UIApplication _run] + 623
29 UIKit 0x00a39c93 UIApplicationMain + 1160
30 app 0x00031342 main + 130
31 app 0x00002a75 start + 53
)
terminate called after throwing an instance of 'NSException'
How do I fix this?
Seems like your code is expecting RootViewController to be a subclass of UINavigationController.
If you didn't write that code, you can make a UINavigationController subclass, and initialize it with your tab bar controller as a root view controller, and hide the navigation bar, I think this would give the results you are looking for.
EmilioPelaez is quite right, I just succeeded with a similar solution like this, and it works!
#implementation MainViewController
- (id)initWithNavigatorURL:(NSURL *)URL query:(NSDictionary *)query {
MainTabBarController *mainTabBarController = [[MainTabBarController alloc] init];
[mainTabBarController setTabURLs:[NSArray arrayWithObjects:
#"tt://firstLink",
#"tt://secondLink",
nil]];
self = [super initWithRootViewController:mainTabBarController];
[mainTabBarController release];
self.navigationBarHidden = YES;
return self;
}
#end
I found another way to make it work (and maybe the better way that reduce code complexity):
inherit UITabBarController with this additional method:
- (UIViewController *)topViewController {
return self;
}
It works perfectly.
is this right
[map from:#"tt://primary" toViewController:[RootViewController class]];
my suggestion is
[map from:#"tt://primary" toViewController:RootViewControllerobject];
Hell All,
I am new to iPhone and struggling with following problem.
When i remove scroll view with following statement my appli crashes.
[scrollView removeFromSuperview];
I am adding uiscrollview with following line.
[self.view addSubview:scrollView];
Hereis the log.
Thread 0 Crashed:
0 libobjc.A.dylib 0x34a80466 objc_msgSend + 18
1 UIKit 0x341aaaa8 -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 152
2 UIKit 0x341aaace -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 190
3 UIKit 0x341aaace -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 190
4 UIKit 0x341c05a0 -[UIView(Hierarchy) removeFromSuperview] + 208
5 UIKit 0x34249a76 -[UIScrollView removeFromSuperview] + 42
6 KabushikiShimbun 0x000387b6 -[PDFPageScrollViewController ReGenerateScrollViewAsperNewData] (PDFPageScrollViewController.m:1451)
7 KabushikiShimbun 0x00038aac -[PDFPageScrollViewController CheckPageUpdationWithDate:] (PDFPageScrollViewController.m:1441)
8 KabushikiShimbun 0x0003c472 -[PDFPageScrollViewController requestFinished:] (PDFPageScrollViewController.m:792)
9 CoreFoundation 0x35818bb8 -[NSObject(NSObject) performSelector:withObject:] + 16
10 KabushikiShimbun 0x0000e9ba -[ASIHTTPRequest reportFinished] (ASIHTTPRequest.m:1945)
11 CoreFoundation 0x35818bb8 -[NSObject(NSObject) performSelector:withObject:] + 16
12 Foundation 0x3118178e __NSThreadPerformPerform + 262
13 CoreFoundation 0x358307d6 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 6
14 CoreFoundation 0x358025b0 __CFRunLoopDoSources0 + 376
15 CoreFoundation 0x35801e54 __CFRunLoopRun + 224
16 CoreFoundation 0x35801c80 CFRunLoopRunSpecific + 224
17 CoreFoundation 0x35801b88 CFRunLoopRunInMode + 52
18 GraphicsServices 0x320c84a4 GSEventRunModal + 108
19 GraphicsServices 0x320c8550 GSEventRun + 56
20 UIKit 0x341dc322 -[UIApplication _run] + 406
21 UIKit 0x341d9e8c UIApplicationMain + 664
22 KabushikiShimbun 0x00002da6 main (main.m:14)
23 KabushikiShimbun 0x00002d70 start + 32
Any Idea ?
Thank you.
Check whether it has a superview before removing from superview;
if([scrollView superview]!=nil){
[scrollView removeFromSuperview];
}
Try this code
for(UIView *view in self.view.subviews)
{
if([view isMemberOfClass:[UIScrollView class]])
{
[scrollview removeFromSuperView];
}
}
Try this code. It's tested.
NSArray *subviews = [[NSArray alloc] initWithArray:self.view.subviews];
for(UIScrollView *subview in subviews) {
[subview removeFromSuperView];
}
[subviews release];
but be carefull it removes all ScrollViews present in your self.view
I have this crash. It is similar to other threads, but not the same.
I would like to show a modal view controller first the user goes to a specific view controller. Following the hints, I do that on - (void) viewDidAppear:(BOOL)animated, and apply a delay as I saw it's recommended.
- (void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self performSelector:#selector(presentMyModal) withObject:nil afterDelay:1];
}
- (void) presentModal{
ModalViewController *modal = [[[ModalViewController alloc] init] autorelease];
[self presentModalViewController:modal animated:YES];
}
Afterwards, ramdomly It crashes. I get this message in console:
<Warning>: *** Assertion failure in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:], /SourceCache/UIKit/UIKit-1447.6.4/UIWindowController.m:186
Thu Feb 3 10:00:44 unknown MyApp[1830] <Error>: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempting to begin a modal transition from <UINavigationController: 0x454260> to <ModalViewController: 0x47af00> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed'
*** Call stack at first throw:
(
0 CoreFoundation 0x3759dc7b __exceptionPreprocess + 114
1 libobjc.A.dylib 0x32d9bee8 objc_exception_throw + 40
2 CoreFoundation 0x3759dac3 +[NSException raise:format:arguments:] + 70
3 Foundation 0x351a3e73 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 62
4 UIKit 0x359e92a8 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 208
5 UIKit 0x359e8c98 -[UIViewController presentModalViewController:withTransition:] + 2792
6 UIKit 0x35a7b51c -[UIViewController _tryRecursivelyPresentModalViewController:withTransition:] + 116
7 UIKit 0x359e84c0 -[UIViewController presentModalViewController:withTransition:] + 784
8 UIKit 0x359e8060 -[UIViewController presentModalViewController:animated:] + 96
9 MyApp 0x0005d57f -[MyAppViewController presentMyModal] + 58
10 Foundation 0x351724db __NSFireDelayedPerform + 366
11 CoreFoundation 0x37552305 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 16
12 CoreFoundation 0x37551cd9 __CFRunLoopDoTimer + 988
13 CoreFoundation 0x37521a91 __CFRunLoopRun + 1184
14 CoreFoundation 0x3752150b CFRunLoopRunSpecific + 226
15 CoreFoundation 0x37521419 CFRunLoopRunInMode + 60
16 GraphicsServices 0x33e76d24 GSEventRunModal + 196
17 UIKit 0x3591d57c -[UIApplication _run] + 588
18 UIKit 0x3591a558 UIApplicationMain + 972
19 MyApp 0x0000e75f main + 50
20 MyApp 0x0000e6e8 start + 52
As you can see, I wait until view is appeared. Is this maybe an OS bug? It seems like it tries to present recursively other modal view controllers, provoquing crashes.
Thanks a lot.
Apart from me being picky in the comment, I thought I could as well help with this one as well. I think you need to search for the culprit somewhere else. I created a new project and a view controller with this snippet:
#import "VC1.h"
#implementation VC1
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self performSelector:#selector(presentModal) withObject:nil afterDelay:1.0];
}
- (void)presentModal {
static int colorChooser = 0;
VC1 *vc1 = [[[VC1 alloc] init] autorelease];
switch (colorChooser%2) {
case 0:
vc1.view.backgroundColor = [UIColor whiteColor];
break;
default:
vc1.view.backgroundColor = [UIColor blackColor];
break;
}
colorChooser++;
[self presentModalViewController:vc1 animated:YES];
}
#end
And it works flawlessly after being pushed on the navigation controller. It is recursively alternating between black and white views, tested both in the sim and on a 3G device.
Maybe you are doing some other view transitions due to some notifications or other asynchronic means? Either way you would need to share more of your code for anyone to tell where the problem is.
Our preferred solution is to use -[UIViewController presentViewController:animated:completion:] and do whatever the next action is (eg presenting another VC) in the completion block.
For example:
[self presentViewController:yourViewController animated:YES completion:^{
[yourViewController presentMyModal];
}];
This method was introduced in iOS 5.0.
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Thread" inManagedObjectContext:managedObjectContext];
That line doesn't seem to work anymore (I'm pretty sure its that line).
I can't seem to work out whats the problem. The application worked perfectly on Xcode with iOS 4.1 and now crashes with this error in the console:
2010-12-07 17:12:27.552 SMSApp[9222:207] +[ persistentStoreCoordinator]: unrecognized selector sent to class 0x5b14580
2010-12-07 17:12:27.553 SMSApp[9222:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[ persistentStoreCoordinator]: unrecognized selector sent to class 0x5b14580'
*** Call stack at first throw:
(
0 CoreFoundation 0x01547be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0169c5c2 objc_exception_throw + 47
2 CoreFoundation 0x015497bb +[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x014b9366 ___forwarding___ + 966
4 CoreFoundation 0x014b8f22 _CF_forwarding_prep_0 + 50
5 CoreData 0x00e6f3ca +[NSEntityDescription entityForName:inManagedObjectContext:] + 42
6 SMSApp 0x000046b9 -[MessagesRootViewController reloadMessages:] + 146
7 SMSApp 0x00004a09 -[MessagesRootViewController viewDidLoad] + 85
8 UIKit 0x0052265e -[UIViewController view] + 179
9 UIKit 0x00520a57 -[UIViewController contentScrollView] + 42
10 UIKit 0x00531201 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48
11 UIKit 0x0052f831 -[UINavigationController _layoutViewController:] + 43
12 UIKit 0x00530b4c -[UINavigationController _startTransition:fromViewController:toViewController:] + 524
13 UIKit 0x0052b606 -[UINavigationController _startDeferredTransitionIfNeeded] + 266
14 UIKit 0x00643e01 -[UILayoutContainerView layoutSubviews] + 226
15 QuartzCore 0x010b4451 -[CALayer layoutSublayers] + 181
16 QuartzCore 0x010b417c CALayerLayoutIfNeeded + 220
17 QuartzCore 0x010ad37c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
18 QuartzCore 0x010ad0d0 _ZN2CA11Transaction6commitEv + 292
19 UIKit 0x0047719f -[UIApplication _reportAppLaunchFinished] + 39
20 UIKit 0x00477659 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 690
21 UIKit 0x00481db2 -[UIApplication handleEvent:withNewEvent:] + 1533
22 UIKit 0x0047a202 -[UIApplication sendEvent:] + 71
23 UIKit 0x0047f732 _UIApplicationHandleEvent + 7576
24 GraphicsServices 0x01b2ca36 PurpleEventCallback + 1550
25 CoreFoundation 0x01529064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
26 CoreFoundation 0x014896f7 __CFRunLoopDoSource1 + 215
27 CoreFoundation 0x01486983 __CFRunLoopRun + 979
28 CoreFoundation 0x01486240 CFRunLoopRunSpecific + 208
29 CoreFoundation 0x01486161 CFRunLoopRunInMode + 97
30 UIKit 0x00476fa8 -[UIApplication _run] + 636
31 UIKit 0x0048342e UIApplicationMain + 1160
32 SMSApp 0x000025c4 main + 102
33 SMSApp 0x00002555 start + 53
)
terminate called after throwing an instance of 'NSException'
Any idea where this error is coming from or what is causing it?
Just to let you know as well, upgrading to XCode with iOS 4.2 caused some of the files to be deleted from my project. I don't know why this was, whether it was because they were linked files and not actually in the folder I dunno.
Any ideas?
Thanks
// EDIT
This method is in the AppDelegate:
- (NSManagedObjectContext *)managedObjectContext {
if (managedObjectContext_ != nil) {
return managedObjectContext_;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
managedObjectContext_ = [[NSManagedObjectContext alloc] init];
[managedObjectContext_ setPersistentStoreCoordinator:coordinator];
}
return managedObjectContext_;
}
// EDIT AGAIN
- (void)reloadMessages:(NSNotification *)notification {
NSLog(#"RECIEVED NEW MESSAGES TO MessagesRootViewController");
NSLog(#"%#",managedObjectContext);
// we need to get the threads from the database...
NSFetchRequest *theReq = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Thread" inManagedObjectContext:self.managedObjectContext];
[theReq setEntity:entity];
threads = [NSArray arrayWithArray:[managedObjectContext executeFetchRequest:theReq error:nil]];
[self.tableView performSelectorOnMainThread:#selector(reloadData) withObject:nil waitUntilDone:NO];
if(notification != nil){ // if its been caused by a notification
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"New Message" message:#"A new message has been received" delegate:nil cancelButtonTitle:#"Thanks" otherButtonTitles:nil];
[alert performSelectorOnMainThread:#selector(show) withObject:nil waitUntilDone:NO];
[alert release];
}
}
// EDIT 3
If I put this code in the applicationDidFinishLoading of my app delegate it works fine!
NSFetchRequest *theReq = [[NSFetchRequest alloc] init];
NSEntityDescription *theEntity = [NSEntityDescription entityForName:#"Thread" inManagedObjectContext:self.managedObjectContext];
[theReq setEntity:theEntity];
NSArray *theThreads = [NSArray arrayWithArray:[self.managedObjectContext executeFetchRequest:theReq error:nil]];
After having a quick look at your code I think I found a couple of parts that needed attention. I'll try and break them down below:
SMSAppAppDelegate
1) Notice that in your interface file, you declare your CoreData variables with an underscore at the end of the variable name. Then you create properties for each of the ivar without the underscore. That is all fine as long as you #synthesize them making the correct assignment, which seems to be missing from your implementation:
#synthesize managedObjectContext=managedObjectContext_;
#synthesize managedObjectModel=managedObjectModel_;
#synthesize persistentStoreCoordinator=persistentStoreCoordinator_;
DownloadContacts
1) In this class you are calling the managedObjectContext directly through the variable. I wouldn't recommend that but this is not your actual problem. Notice that you release the managedObjectContext on dealloc even though you have no ownership of it!
2) What I would do in this case is declare a property for the context and always access it via the property. Also if you rename your instance variable to include an underscore at the end you are minimising your chances of accessing it directly (i.e. without using self.) and it will make it easier for you to find where in this class you are actually doing that (there are a couple of places from memory).
So in your interface file, rename managedObjectContext ivar and declare a property:
NSManagedObjectContext *managedObjectContext_;
...
#property (nonatomic, retain) NSManagedObjectContext managedObjectContext;
And don't forget to make the assignment on #sythesize and release on dealloc, since you are using a retain property:
#synthesize managedObjectContext=managedObjectContext_;
...
[managedObjectContext_ release];
Then if you try and compile you will get two or three errors of unrecognised instance variable which is where you have to go and change it to self.managedObjectContext
MessagesRootViewController
And finally I'd recommend you go through the same process in your MessagesRootViewController but this one should still work fine as is!
See how you go and let me know if any of the above is not clear!
Cheers,
Rog
I'm assuming you're doing something like:
[ClassName persistentStoreCoordinator]
Make sure ClassName is defined and has the persistentStoreCoordinator class method. Perhaps the file that did these things got deleted?
Matt
Your database might be corrupted, try resetting the iOS simulator
by clicking on iOS Simulator>Reset contents and settings.
Edit:
It looks like you're trying to call a selector that doesn't exist. Try figuring out which files were deleted, as it seems like you have a method that is called that can't be found at runtime. Did your core data classes get erased, maybe?