此代码复制到其他任何地方似乎都有效。它只是在我的应用程序内部崩溃。有什么想法吗?
另一个.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 :(得分: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/
答案 1 :(得分:0)
两件事:
<UITableViewDataSource, UITableViewDelegate>
JEntryTableViewController.h
档案