2012-03-12 23 views
-1

此代碼複製到其他地方似乎工作。它只是在我的應用程序崩潰的地方。任何想法爲什麼?我的UITableViewController的實現是如何錯誤的?

另一.M ...

#import "JEntryTableViewController.h" 
@interface JCreateViewController() { 

    JEntryTableViewController *_tableView; 

} 

@property (nonatomic, strong) JEntryTableViewController *tableView; 

@end 

@implementation JCreateViewController 

@synthesize tableView = _tableView; 

- (id)init 
{ 
    self = [super init]; 
    if (self) { 

     self.tableView = [[JEntryTableViewController alloc] initWithStyle:UITableViewStylePlain]; 
     [self.view addSubview:self.tableView.view]; 

    } 
    return self; 
} 

JEntryTableViewController.h:

#import <UIKit/UIKit.h> 


@interface JEntryTableViewController : UITableViewController { 

} 

@end 

JEntryTableViewController.m:

#import "JEntryTableViewController.h" 

@interface JEntryTableViewController() 

@end 

@implementation JEntryTableViewController 

- (id)initWithStyle:(UITableViewStyle)style 
{ 
    self = [super initWithStyle:style]; 
    if (self) { 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
} 

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 5; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"CountryCell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    return cell; 
} 

#pragma mark - Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

} 
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return 60; 
} 

@end 

我跑這是一個快速測試,以確保它被設置正確,令我驚訝的是,當我滾動回到我已經看到的單元格時,它崩潰並給了我一個EXC_BAD_ACCESS錯誤。不幸的是,調試區域並沒有給我任何回報,我可以使用,我真的不知道問題是什麼 - 它是一個基本的簡單的代碼。我不知道該怎麼解決。它應該工作。

+0

在.m中的每段代碼中添加一個nslog,並查看哪些段被調用 – JTApps 2012-03-12 03:48:42

+0

我剛剛做了這個。它調用了所有相關的位,然後我滾動了,它在崩潰之前沒有調用任何額外的東西。 – Andrew 2012-03-12 04:13:52

+1

[UITableView崩潰在滾動上]的可能的雙重職位(http://stackoverflow.com/questions/9661060/uitableview-crashing-on-scroll) – 2012-03-12 04:18:07

回答

1

你實現tableView的方式可能不是我們常用的常用方式。

您可以將tableView直接添加到ViewController中,而無需使用從UITableViewController繼承的其他viewController。

你應該做的和你在JEntryTableViewController中做的一樣。

當遇到EXC_BAD_ACCESS問題時,有幾種解決方案可以找到確切的問題。 1. EXC_BAD_ACCESS signal received http://www.touch-code-magazine.com/how-to-debug-exc_bad_access/

  • 在Xcode中的右側部分break points您可以添加這些類型的破發點,它可以幫助您快速查找異常,你的情況。
  • 0

    兩件事情:

    1. <UITableViewDataSource, UITableViewDelegate>JEntryTableViewController.h文件
    2. 寫下來這裏的崩潰日誌,這樣我們就可以輕鬆解決你的問題。
    相關問題