2012-07-22 23 views
2

일반 뷰 컨트롤러 내부에 (동적) 테이블 뷰가 필요한이 iPhone 프로젝트를 수행하고 있습니다. 페이지에 다른 것들을 넣어야하기 때문에 테이블 뷰 컨트롤러를 선택하지 않았습니다. 텍스트 필드, 버튼 및 약 4-5 셀의 작은 테이블보기가있는 페이지를 상상해보십시오.일반 뷰 컨트롤러 내부의 테이블 뷰

앱을 실행할 때 버튼을 터치하여이보기를 선택해야합니다. 의 I는, 응용 프로그램 충돌 버튼을 클릭하고 나에게 말한다 :

2012년 7월 22일 14 : 40 : 57.304 얼마나 많은 [3055 : F803] 에서 * 어설 션 실패 - [jQuery과 _createPreparedCellForGlobalRow? withIndexPath : 이것은 내하는 .m 파일이

#import <UIKit/UIKit.h> 

@interface ProjectViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> 

@end 

입니다 :

], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061

이 내 .H 파일입니다

#import "ProjectViewController.h" 

@interface ProjectViewController() 

@end 

@implementation ProjectViewController 


//MyViewController.m 
#pragma mark - Table View Data Source 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    NSLog(@"numberOfSectionsInTableView"); 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    NSLog(@"numberOfRowsInSection"); 
    return 5; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(@"cellForRowAtIndexPath"); 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 

    NSLog(@"cellForRowAtIndexPath"); 

    cell.textLabel.text = @"Test"; 

    return cell; 
} 


@end 

위임자와 데이터 소스를 설정하기 위해 테이블보기에서 내 컨트롤러로 컨트롤을 드래그했습니다.

내가 뭘 잘못 했니 ??

도움 주셔서 감사합니다.

+0

.h 파일을 표시 할 수 있습니까? @interface ProjectViewController : UIViewController {}. 이게 그거야? –

+0

질문을 이해할 수 없습니다. 내 .H 파일의 전체 코드는 거기에 내 질문에있다. 나는 그 안에 뭔가 다른 것을 넣고 싶습니까? – anthoprotic

+0

죄송합니다, 그 부분을 그리워합니다 :) –

답변

2

봅니다

@property (nonatomic, strong) IBOutlet UITableView *myTableView; 

ProjectViewController.m 당신의 storyboard

ProjectViewController.h에 tableView.h 파일 및 와이어를에 출구를 만들기 위해

@synthesize myTableView; 

... 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(@"cellForRowAtIndexPath"); 

    UITableViewCell *cell = [self.myTableView dequeueReusableCellWithIdentifier:@"cell"]; 

    NSLog(@"cellForRowAtIndexPath"); 

cell.textLabel.text = @"Test"; 

return cell; 

}

+0

@AnthonyGuay 나의 기쁨 :) Im sleepy, good nite :) –

+0

자, 그건 내 멍청한 실수 야! 나는 테이블 뷰를위한 콘센트를 만들기 위해 열중하고있다. 자, 이제 완벽하게 작동합니다 :) 당신 덕분입니다. 동일한 문제가있는 사용자 : .H 파일에 다음을 추가하십시오. @property (weak, nonatomic) IBOutlet UITableView * tableView; – anthoprotic

+0

너무 많이 편집했기 때문에 내 대답이 귀하의 의견 아래 다시 나타났습니다! 어쨌든 너의 도움에 감사, 좋은 밤! – anthoprotic

0

-cellForRowAtIndexPath에서 이렇게하면 괜찮을 것입니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
NSLog(@"cellForRowAtIndexPath"); 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 

if(cell == nil) 
{ 
    cell = [[UITableViewCell alloc] 
      initWithStyle:UITableViewCellStyleDefault 
      reuseIdentifier:@"cell"]; 
} 

NSLog(@"cellForRowAtIndexPath"); 

cell.textLabel.text = @"Test"; 

return cell; 

}

문제는 휴대가 메모리 할당과 초기화 없었어이다. 그래서 당신은 오류가 발생합니다.