2011-07-25 32 views
0

我有一個tabbar和幾個視圖,其中一個tableview連接到核心數據。現在我已經在另一個項目中創建了一個tableview,並且我想將它合併到我的第一個項目中。這對我來說並不陌生,以前我曾在另一個項目中完成過,在這個項目中,我有三個帶有不同核心數據表的桌面視圖,所有工作都很好。所以我認爲這將是在公園散步。將兩個tableviews與核心數據合併到一個tabbar的問題

在我的AppDelage.m和.h中,我添加並複製了managedObjectContext的所有代碼到managedObjectContext2。並製作了一個新的導航控制器「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; 

然後在我的ProtokollList.m中,我將managedObjectContext更改爲managedObjectContext2。並在MainWindow.nib中建立了必要的連接。

但是當我嘗試運行項目,我收到此錯誤信息:

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' 

我不知道它說,它不承認「ProtokollList」類,因爲它在ProtokollList.h定義。

有沒有人有任何想法?這是發射前的最後一步!

編輯: 如果我嘗試空出:

/* 
ProtokollList *protokollList = (ProtokollList *)[navigationController2 topViewController]; 
    // Set its managedObjectContext property to the managed object context 
    protokollList.managedObjectContext2 = self.managedObjectContext2; 
*/ 

我可以打開這個項目,但是當我點擊ProtokollList-的tableview我得到這個新的錯誤消息:

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' 

最佳問候, xqtr

回答

0

編輯:

我知道臨界點是關於IB的警告(在開始時沒有注意到它)...

你能否檢查ProtokollList.h和ProtokollList.m是否被有效地分配給你正在構建的目標? (我這麼認爲,否則你會有更多的鏈接問題,無論如何,這是一個基本檢查)。

如果這是好的,那麼我只會嘗試一個乾淨的,重建所有。

如果這不能解決問題,那麼這可能意味着鏈接器沒有在最終的二進制文件中包含ProtokollList.m,因爲有一些優化(該類可能永遠不會引用其餘代碼,只是在Interface生成器)。解決方法是將-all_load添加到項目的鏈接器標誌。

如果這沒有幫助,我很傷心,但我沒有更多的建議...

要調用:

protokollList.managedObjectContext2 = self.managedObjectContext2; 

並沒有名爲managedObjectContext2財產protokollList被發現。這可以通過行推斷:

-[UIViewController setManagedObjectContext2:]: unrecognized selector sent to instance 0x4d13c40 

所以,你應該在possilby定義protokollListmanagedObjectContext2(這應該是一個UIViewController)。

編輯;

interface ProtokollList : UITableViewController <NSFetchedResultsControllerDelegate> {   
     NSFetchedResultsController *fetchedResultsController2; 
     NSManagedObjectContext *managedObjectContext2; 
} 
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext2; 
@end 
+0

嗨@sergio,謝謝你的回覆! 在ProtokollList.h我已經定義managedObjectContext2: @接口ProtokollList:的UITableViewController { \t NSFetchedResultsController * fetchedResultsController2; \t NSManagedObjectContext * managedObjectContext2; } @ end 還是我做錯了什麼? – xqtr

+0

你應該丟失的屬性定義,看到我的編輯,不要忘了在'.m'文件中的'@ synthesize' ... – sergio

+0

不行,我得屬性定義爲好,這樣可以不它。 @ property(nonatomic,retain)NSFetchedResultsController * fetchedResultsController2; @ property(nonatomic,retain)NSManagedObjectContext * managedObjectContext2; and @ synthesize fetchedResultsController2,managedObjectContext2; – xqtr