1

多くのトピックを読みましたが、何も機能しません。コードはありますが、セルをクリックすると次のエラーが表示されます: *** -[ModeViewController tableView:didSelectRowAtIndexPath:]: message sent to deallocated instance 0x764df40
Code:
ModeViewController.h

@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);
}

何が問題なのですか?
前もって感謝します。

4

2 に答える 2

2

-[ModeViewController tableView:didSelectRowAtIndexPath:]: 割り当て解除されたインスタンス 0x764df40 に送信されたメッセージ

このメッセージは、「didSelectRowAtIndexPath:」に問題があることを示しているのではなく、「ModeViewController」のインスタンスに問題があることを示しています。このインスタンスは、メソッド「didSelectRowAtIndexPath:」が呼ばれています。

したがって、問題は ModeViewController インスタンスの寿命に関するものです。

コントローラーがどこでどのように作成および保存されているかを教えてください。

于 2013-04-07T16:58:37.983 に答える