我已经阅读了很多主题,但是我没有任何作用。 我有一个代码,但是当我点击一个单元格我得到这个错误: *** -[ModeViewController tableView:didSelectRowAtIndexPath:]: message sent to deallocated instance 0x764df40
代码:
ModeViewController.htableView:didSelectRowAtIndexPath - 发送到释放实例的消息
@interface ModeViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableViewModeSelection;
@end
ModeViewController.m
@implementation ModeViewController
@synthesize tableViewModeSelection;
- (void)viewDidLoad
{
tableViewModeSelection = [[UITableView alloc] initWithFrame:CGRectMake(10, 80, screenRect.size.width - 20, screenRect.size.height - 90) style:UITableViewStyleGrouped];
tableViewModeSelection.dataSource = self;
tableViewModeSelection.delegate = self;
[self.view addSubview:tableViewModeSelection];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text = [modes objectAtIndex:indexPath.row];
cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Selected at row: %i", indexPath.row);
}
可能是什么问题?
在此先感谢。
我不知道解决方案,但只是在一个侧面说明,'@interface WoLKiModeViewController:UIViewController''和'@implementation ModeViewController'。他们不一定是相似的吗?我的意思是'@implementation WoLKiModeViewController' –
Zen
2013-04-07 16:05:54
现在它是相似的。我犯了一个错误。它必须是'ModeViewController'。 – 2013-04-07 17:01:14