2013-04-07 2 views
1

많은 주제를 읽었지만 아무 것도 작동하지 않습니다. 나는 코드를 가지고,하지만 난 셀을 클릭 할 때이 오류가 얻을 : *** -[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); 
} 

문제가 될 수 무엇 ?
미리 감사드립니다.

+0

솔루션을 모르지만 사이드 노트, UIViewController 및 @implementation ModeViewController'를주의 깊게 읽습니다. 그들은 유사해야하지 않습니까? '@implementation WoLKiModeViewController' – Zen

+0

이제는 비슷합니다. 제가 실수를. 그것은'ModeViewController' 여야합니다. –

답변

2

-[ModeViewController tableView:didSelectRowAtIndexPath:]: message sent to deallocated instance 0x764df40

이 메시지에 문제가 있음을 말하지 않는다 "didSelectRowAtIndexPath는"그것은 (더 이상 존재하지 않는) 해제된다 "ModeViewController"의 인스턴스에 문제가 있음을 말 메소드 "didSelectRowAtIndexPath :"가 호출됩니다.

그래서 문제는 ModeViewController 인스턴스의 수명에 관한 것입니다.

컨트롤러가 생성되고 저장되는 위치와 방법을 표시 할 수 있습니까?

+0

UIScrollView에'ModeViewController'가 있습니다. 그래서 그것은 더 일찍 설정됩니다. 그것이 문제일까요? 어떻게 해결할 수 있을까요? –

+0

@Luuksweb 어떻게 설정합니까? 이 오류는 아무도 컨트롤러에 대한 강력한 포인터가 없음을 나타냅니다. 그런데 컨트롤러는 UIScrollView 안에 들어갈 수 없으며 컨트롤러는 뷰가 아닙니다. 뷰는 스크롤 뷰 내부로 이동할 수 있지만 컨트롤러 자체에서는 볼 수 없습니다. 어쩌면 그것은 당신의 혼란의 원천 일 것입니다. –

+0

viewController 자체를 추가 할 수 없기 때문에 viewController에서 뷰를 추가하는 것이 좋습니다. 이 문제를 어떻게 해결할 수 있습니까? –

0

아마도 여러분은 scrollview에 ModeViewController의 뷰를 추가하고 있지만, 실제로는 tableview의 delegate 인 ModeViewController 인스턴스 자체를 해제하고있을 것입니다. 그래서 예외가오고 있습니다. 해결 방법은보기가 존재할 때까지 ModeViewController의 인스턴스를 해제하지 않는 것일 수 있습니다.

+0

ARC를 사용하므로 변경할 수 없습니다. –