2011-01-08 29 views
0

我正在試圖讓我的應用程序重新開始工作,目前我正在將自己的頭撞向磚牆。使用UITableView的問題

我想要做的就是當我的搜索tableview中的一行被選中時顯示UIActionSheet。人們可能會認爲簡單的任務......似乎不是。

當我在模擬器上啓動應用程序時,它在SIGABRT之前甚至加載了rootViewController(下面的StackTrace)。我完全不知道從哪裏開始挖掘。

我的應用程序的委託方法 「didFinishLaunchingWithOptions」 貫穿順利,最後一個斷點,我可以在我的代碼設置,這是一個:

OverviewViewController.m:

- (void)viewWillAppear:(BOOL)animated 
{ 
    // this it the last breakable line, jumping over it leads to the SIGABRT 
    [super viewWillAppear:animated]; 
    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addNewItem:)]; 
    [[self navigationItem] setRightBarButtonItem:addButton]; 
    [addButton release]; 
} 

OverviewViewController是我NavigationControllers RootViewController的,無論是在應用程序的委託方法didFinishLaunchingWithOptions中初始化。

AppDelegate.m

OverviewViewController *ovController = [[OverviewViewController alloc] init]; 

(omitting initialization code for ovController) 

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:ovController]; 
[ovController release]; 

NSArray *tabViews = [NSArray arrayWithObjects:navController, (my other controllers), nil]; 
[navController release]; 

[tabController setViewControllers:tabViews]; 
[window setRootViewController:tabController]; 

錯誤開始彈出i之後開始執行使用標準的UITableViewDelegate和UITableViewDateSourceDelegate方法完全不同的視圖(SearchControllerView)。這個視圖甚至不在啓動時加載,只有當點擊某個按鈕時纔會加載。

堆棧跟蹤:

2011-01-08 13:22:21.279 ReleaseDate[5295:207] -[UITableView _saveOpaqueViewState:]: unrecognized selector sent to instance 0x502e000 
2011-01-08 13:22:21.282 ReleaseDate[5295:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableView _saveOpaqueViewState:]: unrecognized selector sent to instance 0x502e000' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x0118bbe9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x012e05c2 objc_exception_throw + 47 
    2 CoreFoundation      0x0118d6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
    3 CoreFoundation      0x010fd366 ___forwarding___ + 966 
    4 CoreFoundation      0x010fcf22 _CF_forwarding_prep_0 + 50 
    5 UIKit        0x006745b3 -[UITableViewRowData initWithTableView:] + 285 
    6 UIKit        0x0052eae3 -[UITableView(_UITableViewPrivate) _updateRowData] + 84 
    7 UIKit        0x0052a6da -[UITableView numberOfSections] + 39 
    8 UIKit        0x006c25ee -[UITableViewController viewWillAppear:] + 100 
    9 ReleaseDate       0x00003364 -[OverviewViewController viewWillAppear:] + 68 
    10 UIKit        0x00579c9a -[UINavigationController _startTransition:fromViewController:toViewController:] + 858 
    11 UIKit        0x00574606 -[UINavigationController _startDeferredTransitionIfNeeded] + 266 
    12 UIKit        0x0068ce01 -[UILayoutContainerView layoutSubviews] + 226 
    13 QuartzCore       0x01f25451 -[CALayer layoutSublayers] + 181 
    14 QuartzCore       0x01f2517c CALayerLayoutIfNeeded + 220 
    15 QuartzCore       0x01f1e37c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310 
    16 QuartzCore       0x01f1e0d0 _ZN2CA11Transaction6commitEv + 292 
    17 UIKit        0x004c019f -[UIApplication _reportAppLaunchFinished] + 39 
    18 UIKit        0x004c0659 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 690 
    19 UIKit        0x004cadb2 -[UIApplication handleEvent:withNewEvent:] + 1533 
    20 UIKit        0x004c3202 -[UIApplication sendEvent:] + 71 
    21 UIKit        0x004c8732 _UIApplicationHandleEvent + 7576 
    22 GraphicsServices     0x0199da36 PurpleEventCallback + 1550 
    23 CoreFoundation      0x0116d064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
    24 CoreFoundation      0x010cd6f7 __CFRunLoopDoSource1 + 215 
    25 CoreFoundation      0x010ca983 __CFRunLoopRun + 979 
    26 CoreFoundation      0x010ca240 CFRunLoopRunSpecific + 208 
    27 CoreFoundation      0x010ca161 CFRunLoopRunInMode + 97 
    28 UIKit        0x004bffa8 -[UIApplication _run] + 636 
    29 UIKit        0x004cc42e UIApplicationMain + 1160 
    30 ReleaseDate       0x00002ac4 main + 102 
    31 ReleaseDate       0x00002a55 start + 53 
) 
terminate called after throwing an instance of 'NSException' 

任何人可以幫助我得到正確的軌道上?我真的開始發瘋了這一個...

UPDATE

執行的cellForRowAtIndexPath的:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"]; 
    if (!cell) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"UITableViewCell"] autorelease]; 
    } 

    // set search item information 
    WebSearchItem *wsi = [self.searchData objectAtIndex:[indexPath row]]; 
    [[cell textLabel] setText:[wsi title]]; 
    [[cell detailTextLabel] setText:[NSString stringWithFormat:@"%@ - %@", [wsi descText], [[wsi releaseDate] dateToString:@"yyyy-MM-dd"]]]; 
    [cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton]; 

    return cell; 
} 

的OverviewViewController.m初始化方法實現

- (id)init 
{ 
    [super initWithStyle:UITableViewStyleGrouped]; 
    [[self navigationItem] setTitle:@"ReleaseDate"];  
    return self; 
} 

-(id)initWithStyle:(UITableViewStyle)style 
{ 
    return [self init]; 
} 

UPDATE 2

OverviewViewController.h

@interface OverviewViewController : UITableViewController { 
    ... 
} 

SearchViewController.h

@interface SearchViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate, UIActionSheetDelegate> { 
    IBOutlet UITableView *tableView; 
    ... 
} 

@property (nonatomic, retain) IBOutlet UITableView *tableView; 
+0

你可以分享實現你的`tableView:cellForRowAtIndexPath:`UITableViewDataSource委託方法的代碼嗎?我猜你會返回一個類型爲`UITableView`的錯誤類型的對象,這應該是別的。 – mvds 2011-01-08 13:13:34

+0

我(和我:谷歌)認爲`saveOpaqueViewState`通常在`UITableViewCell`對象上調用。 – mvds 2011-01-08 13:14:34

回答

0

答案是例外:

2011-01-08 13:22:21.279 ReleaseDate[5295:207] -[UITableView _saveOpaqueViewState:]: 
         unrecognized selector sent to instance 0x502e000 
2011-01-08 13:22:21.282 ReleaseDate[5295:207] *** Terminating app due to uncaught 
         exception 'NSInvalidArgumentException', reason: '-[UITableView 
         _saveOpaqueViewState:]: unrecognized selector sent to 
         instance 0x502e000' 

這是說,有些對象(即:UITableView對象,分配在內存地址0x502e000)發送了一個消息(「選擇器」,即一個方法被調用),它不明白。該消息是_saveOpaqueViewState:。谷歌搜索你會發現這個選擇器通常在UITableViewCell實例上調用。

這可能意味着您在某處返回了UITableView,您應該返回UITableViewCell

請看看(或股本)你有

-(UITableViewCell*)tableView:(UITableView*)tv cellForRowAtIndexPath:(NSIndexPath*)ip 
{ 
} 

,看看編譯器不給一些警告那裏的代碼。

更新好的看到你的代碼,我們可以得出結論,這個理論不適用。另一種選擇是過早釋放對象,以便發送到某個UITableViewCell(已消失)的消息結束於另一個對象,順便說一句是UITableView。你可以嘗試,並設置NSZombiesEnabled,或者,作爲第一速戰速決,放線cellForRowAtIndexPath:

NSLog(@"returning table view cell at addr %p for indexpath %@",cell,indexPath); 

然後你就可以比較地址登錄那裏從堆棧跟蹤的地址,只是作爲一個開始。

update2還有另一種理論:那麼兩個UITableViewController對象有自己的UITableView對象嗎?我會想象有兩個控制器試圖在一個表視圖上工作會導致一些不一致。