2012-03-27 43 views
1

我有一個從筆尖建成並設置爲MainWindow類如下:的iOS重複的/殭屍視圖控制器被引用

- (void)applicationDidFinishLaunching:(UIApplication *)application 
{ 
    MainViewController *mainView = [[MainViewController alloc] initWithNibName:@"MainViewController" 
                     bundle:nil]; 
    if(!mainView) 
    { 
     return; 
    } 
    naviController = [[UINavigationController alloc] initWithRootViewController:mainView]; 
    [naviController setToolbarHidden:YES]; 
    [[naviController navigationBar] setTintColor:[UIColor blackColor]]; 
    [[naviController toolbar] setTintColor:[UIColor blackColor]]; 
    [self.window setRootViewController:naviController]; 
    [self.window makeKeyAndVisible]; 
} 

這個工程並正確顯示MainViewController,但是當我嘗試向下滾動在MainViewController的表格視圖中,它會拋出一個EXC_BAD_ACCESS。顯然UIKit是指第二個MainViewController內置於[self.window makeKeyAndVisible];我不明白爲什麼它引用了我通過initWithRootViewController:mainView

以下是兩個MainViewControllers。第一個我初始化,第二個創建在makeKeyAndVisible

enter image description here

這裏是被稱爲殭屍第二MainViewController

enter image description here

上爲什麼發生這種情況的任何想法?

按照要求:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    MainViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainViewCell"]; 
    int i = [indexPath row]; 
    NSLog(@"%d\n",i); 
    if (cell == nil) { 
     // Create a temporary UIViewController to instantiate the custom cell. 
     UIViewController *temporaryController = [[UIViewController alloc] initWithNibName:@"MainViewCell" bundle:nil]; 
     // Grab a pointer to the custom cell. 
     cell = (MainViewCell *)temporaryController.view; 
     // Release the temporary UIViewController. 
     [temporaryController release]; 
    } 
    [[cell icon] setImage:[UIImage imageNamed:[[moduleXMLList objectAtIndex:i] objectForKey:@"thumbnail"]]]; 
    [[cell title] setText:[[moduleXMLList objectAtIndex:i] objectForKey:@"title"]]; 
    [[cell description] setText:[[moduleXMLList objectAtIndex:i] objectForKey:@"description"]]; 
    return cell; 
} 
+0

你有沒有嘗試清洗所有的目標? – 2012-03-27 21:12:53

+0

現在我有。它有相同的結果。 – Kyle 2012-03-27 21:17:27

+0

除此之外,通常解決這些問題的方法是在模擬器中重置內容和設置,重新啓動Xcode,並重新啓動計算機。 – 2012-03-27 21:19:28

回答

1

的問題是,我是用文件的所有者爲MainViewController同時具有對象下的第二UIViewController中。這是錯誤的,所以一旦我擺脫了對象,並使用文件的所有者它就像一個魅力。