Problem copying NSMutableArray - iphone

I am trying to copy one array to another:
NSMutableArray *itemsCopy = [[NSMutableArray alloc] initWithArray:self.items copyItems:YES];
but I get the error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Item copyWithZone:]: unrecognized selector sent to instance 0x5a74900'
*** Call stack at first throw:
(
0 CoreFoundation 0x025afc99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x026fd5de objc_exception_throw + 47
2 CoreFoundation 0x025b17ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x02521496 ___forwarding___ + 966
4 CoreFoundation 0x02521052 _CF_forwarding_prep_0 + 50
5 CoreFoundation 0x025108fa -[NSObject(NSObject) copy] + 42
6 CoreFoundation 0x025ab732 -[NSArray initWithArray:range:copyItems:] + 290
7 CoreFoundation 0x02513963 -[NSArray initWithArray:copyItems:] + 99
8 MyViewController 0x0000787d -[MyViewController tableView:didSelectRowAtIndexPath:] + 258
9 UIKit 0x003968f8 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
10 UIKit 0x0038d1de -[UITableView _userSelectRowAtIndexPath:] + 219
11 Foundation 0x000a404e __NSFireDelayedPerform + 441
12 CoreFoundation 0x025910c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
13 CoreFoundation 0x02592704 __CFRunLoopDoTimer + 1364
14 CoreFoundation 0x024ef089 __CFRunLoopRun + 1817
15 CoreFoundation 0x024ee600 CFRunLoopRunSpecific + 208
16 CoreFoundation 0x024ee521 CFRunLoopRunInMode + 97
17 GraphicsServices 0x02db52c8 GSEventRunModal + 217
18 GraphicsServices 0x02db538d GSEventRun + 115
19 UIKit 0x00332e8f UIApplicationMain + 1160
20 MyViewController 0x0000210c main + 102
21 MyViewController 0x0000209d start + 53
)
terminate called after throwing an instance of 'NSException'

You need to make sure all the contents of self.items adopt the NSCopying protocol.
If you just want a shallow copy, send the -mutableCopy message to self.items.
NSMutableArray *itemsCopy = [self.items mutableCopy];

You have to provide your classes with the copyWithZone selector (according to NSCopying protocol) if you are not copying objects that implement that protocol by default.
So if you are copying custom objects you have to implement it. The copy method always calls copyWithZone.. and you must always provide the implementation, it can't know what to copy inside objects by itself..

Related

getting error when presenting view controller

i am getting this error when trying to presenting view controller. actuallly i am testing this project on ios 4.3 simulator.on other simuators it works fine. this is non arc project. which is supported for ios 4.3 and onward.
request on uploadmanager:<NSMutableURLRequest http://www.livebinders.com/filetree/ipad>
2013-10-12 14:00:54.690 LiveBinders[1703:13b03] -[UploadManagerViewController presentViewController:animated:]: unrecognized selector sent to instance 0x6605a30
2013-10-12 14:00:54.695 LiveBinders[1703:13b03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UploadManagerViewController presentViewController:animated:]: unrecognized selector sent to instance 0x6605a30'
*** Call stack at first throw:
(
0 CoreFoundation 0x01ca85a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x017bc313 objc_exception_throw + 44
2 CoreFoundation 0x01caa0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x01c19966 ___forwarding___ + 966
4 CoreFoundation 0x01c19522 _CF_forwarding_prep_0 + 50
5 LiveBinders 0x0003baa8 -[UploadManagerViewController openEvernote] + 248
6 LiveBinders 0x00068e4b -[TableVC tableView:didSelectRowAtIndexPath:] + 171
7 UIKit 0x00b97b68 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
8 UIKit 0x00b8db05 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
9 Foundation 0x012a779e __NSFireDelayedPerform + 441
10 CoreFoundation 0x01c898c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
11 CoreFoundation 0x01c8ae74 __CFRunLoopDoTimer + 1220
12 CoreFoundation 0x01be72c9 __CFRunLoopRun + 1817
13 CoreFoundation 0x01be6840 CFRunLoopRunSpecific + 208
14 CoreFoundation 0x01be6761 CFRunLoopRunInMode + 97
15 GraphicsServices 0x01dfc1c4 GSEventRunModal + 217
16 GraphicsServices 0x01dfc289 GSEventRun + 115
17 UIKit 0x00b2ec93 UIApplicationMain + 1160
18 LiveBinders 0x0000285d main + 93
19 LiveBinders 0x000027b5 start + 53
<----- calling this method on presenting new view controller ---->
-(void)openEvernote
{
self.dropboxShareLink = NULL;
self.dropBoxFileName = NULL;
EverNoteVC *everNoteVC = [[EverNoteVC alloc]initWithNibName:#"EverNoteView" bundle:nil];
everNoteVC.delegate = (id)self;
if (popoverController.isPopoverVisible) {
[popoverController dismissPopoverAnimated:NO];
}
[self presentViewController:everNoteVC animated:YES ];
[everNoteVC release];
}
presentViewController is not available in iOS versions prior 5.0.
Try with
[self presentModalViewController:everNoteVC animated:YES];
instead.

Problems merging two tableviews into a tabbar with Core Data

I have one tabbar with several views, one with a tableview connected to Core Data. Now I've made one more tableview in a different project, and I want to merge it to my first project. This isn't new to me, I've done it before in another project where I had three tableviews with different core data tables, all working good. So I thought this would be a walk in the park.
In my AppDelage.m and .h I've added and copied all the code for the managedObjectContext to managedObjectContext2. And made a new navigation controller, "navigationController2".
ProtokollList *protokollList = (ProtokollList *)[navigationController2 topViewController];
// Set its managedObjectContext property to the managed object context
protokollList.managedObjectContext2 = self.managedObjectContext2;
// Get the root view controller; it's in the topViewController property of the navigation controller
KortKategori *kortKategori = (KortKategori *)[navigationController topViewController];
// Set its managedObjectContext property to the managed object context
kortKategori.managedObjectContext = self.managedObjectContext;
And then in my ProtokollList.m I've changed managedObjectContext to managedObjectContext2. And made necessary connections in MainWindow.nib.
But when I try to run the project I get this error message:
2011-07-24 18:22:58.188 Kortspel[1346:207] Unknown class ProtokollList in Interface Builder file.
2011-07-24 18:22:58.198 Kortspel[1346:207] -[UIViewController setManagedObjectContext2:]: unrecognized selector sent to instance 0x4d13c40
2011-07-24 18:22:58.199 Kortspel[1346:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController setManagedObjectContext2:]: unrecognized selector sent to instance 0x4d13c40'
*** Call stack at first throw:
(
0 CoreFoundation 0x00fab5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x010ff313 objc_exception_throw + 44
2 CoreFoundation 0x00fad0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00f1c966 ___forwarding___ + 966
4 CoreFoundation 0x00f1c522 _CF_forwarding_prep_0 + 50
5 Kortspel 0x00001f28 -[KortAppDelegate applicationDidFinishLaunching:] + 709
6 UIKit 0x002c4ce2 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1252
7 UIKit 0x002c6d88 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
8 UIKit 0x002d1617 -[UIApplication handleEvent:withNewEvent:] + 1533
9 UIKit 0x002c9abf -[UIApplication sendEvent:] + 71
10 UIKit 0x002cef2e _UIApplicationHandleEvent + 7576
11 GraphicsServices 0x01903992 PurpleEventCallback + 1550
12 CoreFoundation 0x00f8c944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
13 CoreFoundation 0x00eeccf7 __CFRunLoopDoSource1 + 215
14 CoreFoundation 0x00ee9f83 __CFRunLoopRun + 979
15 CoreFoundation 0x00ee9840 CFRunLoopRunSpecific + 208
16 CoreFoundation 0x00ee9761 CFRunLoopRunInMode + 97
17 UIKit 0x002c67d2 -[UIApplication _run] + 623
18 UIKit 0x002d2c93 UIApplicationMain + 1160
19 Kortspel 0x00001c40 main + 102
20 Kortspel 0x00001bd1 start + 53
)
terminate called after throwing an instance of 'NSException'
I don't know it says that it doesn't recognize "ProtokollList" class, because it's defined in ProtokollList.h.
Does anyone have any idea? This is the last step before launching!
EDIT:
If I try to blank out:
/*
ProtokollList *protokollList = (ProtokollList *)[navigationController2 topViewController];
// Set its managedObjectContext property to the managed object context
protokollList.managedObjectContext2 = self.managedObjectContext2;
*/
I can open the project, but when I click on ProtokollList-tableview I get this new error message:
2011-07-25 20:06:56.588 Kortspel[3205:207] Unknown class ProtokollList in Interface Builder file.
2011-07-25 20:07:01.585 Kortspel[3205:207] -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x590f3f0
2011-07-25 20:07:01.587 Kortspel[3205:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x590f3f0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00fb25a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x01106313 objc_exception_throw + 44
2 CoreFoundation 0x00fb40bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00f23966 ___forwarding___ + 966
4 CoreFoundation 0x00f23522 _CF_forwarding_prep_0 + 50
5 UIKit 0x004882b7 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1834
6 UIKit 0x00485d88 -[UITableViewRowData numberOfRows] + 108
7 UIKit 0x00339677 -[UITableView noteNumberOfRowsChanged] + 132
8 UIKit 0x00346708 -[UITableView reloadData] + 773
9 UIKit 0x00343844 -[UITableView layoutSubviews] + 42
10 QuartzCore 0x01f52a5a -[CALayer layoutSublayers] + 181
11 QuartzCore 0x01f54ddc CALayerLayoutIfNeeded + 220
12 QuartzCore 0x01efa0b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
13 QuartzCore 0x01efb294 _ZN2CA11Transaction6commitEv + 292
14 QuartzCore 0x01efb46d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
15 CoreFoundation 0x00f9389b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
16 CoreFoundation 0x00f286e7 __CFRunLoopDoObservers + 295
17 CoreFoundation 0x00ef11d7 __CFRunLoopRun + 1575
18 CoreFoundation 0x00ef0840 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x00ef0761 CFRunLoopRunInMode + 97
20 GraphicsServices 0x019091c4 GSEventRunModal + 217
21 GraphicsServices 0x01909289 GSEventRun + 115
22 UIKit 0x002d9c93 UIApplicationMain + 1160
23 Kortspel 0x00002524 main + 102
24 Kortspel 0x000024b5 start + 53
)
terminate called after throwing an instance of 'NSException'
Best regards,
xqtr
EDIT:
I understand that the critical point is the warning about IB (did not notice it at start)...
Could you check that ProtokollList.h and ProtokollList.m are effectively assigned to the target you are building? (I think so, otherwise you would have more linking problems, anyway, this is a basic check).
If this is ok, then I would simply try a clean and rebuild all.
If this does not fix the problem, then this might mean that the linker is not including ProtokollList.m in the final binary because of some optimization (the class is possibly never referenced in the rest of your code, just in Interface Builder). The fix for this is adding -all_load to the linker flags of your project.
If this does not help, I am very sad but I have no more suggestions...
You are calling:
protokollList.managedObjectContext2 = self.managedObjectContext2;
and no property named managedObjectContext2 is found in protokollList. This can be inferred by the line:
-[UIViewController setManagedObjectContext2:]: unrecognized selector sent to instance 0x4d13c40
So, you should possilby define managedObjectContext2 in protokollList (which should be a UIViewController).
EDIT;
interface ProtokollList : UITableViewController <NSFetchedResultsControllerDelegate> {
NSFetchedResultsController *fetchedResultsController2;
NSManagedObjectContext *managedObjectContext2;
}
#property (nonatomic, retain) NSManagedObjectContext *managedObjectContext2;
#end

UITable cellForRowAtIndexPath

New in iOS, here is Question:
I am using xcode 4.0.2 iso-4.3.2.
Here I have a table and I am creating one mutable array like
mainarray=[[NSMutableArray alloc]initWithObjects:#"Hi",#"Hello"nil];
and sending that value to.Table delegate method like
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
here value is coming but once I am sending dynamically value to the mainarray like
mainarray=[[NSMutableArray alloc]initWithObjects:[dataarray valueForKey:#"first_name"],nil]; or
[mainarray addobject:[dataarray valueForKey:#"first_name"]]
and sending that mainarray value to cell.textlabel.text then my program is terminating and sending this error message.
2011-05-11 10:29:10.346 picture:vide[742:207] -[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x4e85200
2011-05-11 10:29:10.348 picture:vide[742:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x4e85200'
*** Call stack at first throw:
(
0 CoreFoundation 0x00ddb5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f2f313 objc_exception_throw + 44
2 CoreFoundation 0x00ddd0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d4c966 ___forwarding___ + 966
4 CoreFoundation 0x00d4c522 _CF_forwarding_prep_0 + 50
5 UIKit 0x003ecafc -[UILabel setText:] + 72
6 picture:vide 0x000050c9 -[VideoChatController1 tableView:cellForRowAtIndexPath:] + 376
7 UIKit 0x00340b98 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
8 UIKit 0x003364cc -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
9 UIKit 0x0034b8cc -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
10 UIKit 0x0034390c -[UITableView layoutSubviews] + 242
11 QuartzCore 0x01d7ba5a -[CALayer layoutSublayers] + 181
12 QuartzCore 0x01d7dddc CALayerLayoutIfNeeded + 220
13 QuartzCore 0x01d230b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
14 QuartzCore 0x01d24294 _ZN2CA11Transaction6commitEv + 292
15 QuartzCore 0x01d2446d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
16 CoreFoundation 0x00dbc89b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
17 CoreFoundation 0x00d516e7 __CFRunLoopDoObservers + 295
18 CoreFoundation 0x00d1a1d7 __CFRunLoopRun + 1575
19 CoreFoundation 0x00d19840 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x00d19761 CFRunLoopRunInMode + 97
21 GraphicsServices 0x017321c4 GSEventRunModal + 217
22 GraphicsServices 0x01732289 GSEventRun + 115
23 UIKit 0x002d9c93 UIApplicationMain + 1160
24 picture:vide 0x00002910 main + 102
25 picture:vide 0x000028a1 start + 53
)
Please, help.
Here you are getting this terminating log because
dataArray is an NSArray you can't call [dataarray valueForKey:#"first_name"] this
because this unreconised for NSArray
rether than this you may use some thing like this
[[dataarray objectAtIndex:index] valueForKey:#"first_name"]
[__NSArrayI isEqualToString:]: is the issue. You are using the isEqualToString: for an array somewhere. Check that. Its a method of NSString
Initialization of array was wrong.
Following line
mainarray=[[NSMutableArray alloc]initWithObjects:#"Hi",#"Hello"nil];
should be corrected as
mainarray=[[NSMutableArray alloc]initWithObjects:#"Hi",#"Hello" , nil];
Please note the new comma between #"Hello" and nil

Error in dismissing a modal view controller

I have encountered application termination while dismissing a modal view controller.
-[NSCFString window]: unrecognized selector sent to instance 0x6337dc0
2011-06-03 13:26:37.980 Tuscany[19657:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString window]: unrecognized selector sent to instance 0x6337dc0'
*** Call stack at first throw:
(
0 CoreFoundation 0x016ffbe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x018545c2 objc_exception_throw + 47
2 CoreFoundation 0x017016fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x01671366 ___forwarding___ + 966
4 CoreFoundation 0x01670f22 _CF_forwarding_prep_0 + 50
5 UIKit 0x003f4024 -[UIViewController viewControllerForRotation] + 81
6 UIKit 0x003ee8ab -[UIViewController shouldWindowUseOnePartInterfaceRotationAnimation:] + 34
7 UIKit 0x00368dd5 -[UIWindow _clientsForRotation] + 350
8 UIKit 0x0036b87b -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 141
9 UIKit 0x005eb948 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 1053
10 UIKit 0x003f7682 -[UIViewController _dismissModalViewControllerWithTransition:from:] + 2075
11 UIKit 0x003f4324 -[UIViewController dismissModalViewControllerWithTransition:] + 579
12 Foundation 0x000c37f6 __NSFireDelayedPerform + 441
13 CoreFoundation 0x016e0fe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
14 CoreFoundation 0x016e2594 __CFRunLoopDoTimer + 1220
15 CoreFoundation 0x0163ecc9 __CFRunLoopRun + 1817
16 CoreFoundation 0x0163e240 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x0163e161 CFRunLoopRunInMode + 97
18 GraphicsServices 0x01d88268 GSEventRunModal + 217
19 GraphicsServices 0x01d8832d GSEventRun + 115
20 UIKit 0x0035342e UIApplicationMain + 1160
21 Tuscany 0x00002878 main + 102
22 Tuscany 0x00002809 start + 53
)
terminate called after throwing an instance of 'NSException'
Above is the crash log. Please help.
Thanks in advance.
From you log it seems that you are calling window on an NSCFString. NSCFString does not have a window selector, and the compiler would complain if you try and do so, so it is likely that you are sending that message to a deallocated object (imagine that a new object has been allocated where another one was previously), or you are messing with casts.
In case you suspect that you are sending the message to a deallocated object, enable NSZombies.
Without seeing the code, it is not possible to help you further, though.

iOS: Displaying a new modal view on top of master (root) view in split view

I need to call a new modal view in the master view area after selecting a specific object from the initial list (tableview).
Tried this:
//new view init:
clientList *clientListCon = [[clientList alloc] initWithNibName:#"clientList" bundle:nil];
//pushing
[[splitViewController.viewControllers objectAtIndex:0] presentModalViewController:clientListCon animated:YES];
All I get:
MultipleDetailViews[12997:40b] -[UITableView presentModalViewController:animated:]: unrecognized selector sent to instance 0x584d800
2011-03-18 14:40:51.449 MultipleDetailViews[12997:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableView presentModalViewController:animated:]: unrecognized selector sent to instance 0x584d800'
*** Call stack at first throw:
(
0 CoreFoundation 0x017035a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x01857313 objc_exception_throw + 44
2 CoreFoundation 0x017050bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x01674966 ___forwarding___ + 966
4 CoreFoundation 0x01674522 _CF_forwarding_prep_0 + 50
5 MultipleDetailViews 0x00008051 -[RootViewController tableView:didSelectRowAtIndexPath:] + 354
6 UIKit 0x00a8fb68 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
7 UIKit 0x00a85b05 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
8 Foundation 0x0079779e __NSFireDelayedPerform + 441
9 CoreFoundation 0x016e48c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
10 CoreFoundation 0x016e5e74 __CFRunLoopDoTimer + 1220
11 CoreFoundation 0x016422c9 __CFRunLoopRun + 1817
12 CoreFoundation 0x01641840 CFRunLoopRunSpecific + 208
13 CoreFoundation 0x01641761 CFRunLoopRunInMode + 97
14 GraphicsServices 0x0205a1c4 GSEventRunModal + 217
15 GraphicsServices 0x0205a289 GSEventRun + 115
16 UIKit 0x00a26c93 UIApplicationMain + 1160
17 MultipleDetailViews 0x000069a4 main + 102
18 MultipleDetailViews 0x00006935 start + 53
)
terminate called after throwing an instance of 'NSException'
It seems like it ought to be:
[self presentModalViewController:clientListCon animated:YES];
I have no idea how you are getting a reference to a UITableView from the provided code though.