此代碼複製到其他地方似乎工作。它只是在我的應用程序崩潰的地方。任何想法爲什麼?我的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錯誤。不幸的是,調試區域並沒有給我任何回報,我可以使用,我真的不知道問題是什麼 - 它是一個基本的簡單的代碼。我不知道該怎麼解決。它應該工作。
在.m中的每段代碼中添加一個nslog,並查看哪些段被調用 – JTApps 2012-03-12 03:48:42
我剛剛做了這個。它調用了所有相關的位,然後我滾動了,它在崩潰之前沒有調用任何額外的東西。 – Andrew 2012-03-12 04:13:52
[UITableView崩潰在滾動上]的可能的雙重職位(http://stackoverflow.com/questions/9661060/uitableview-crashing-on-scroll) – 2012-03-12 04:18:07