2012-08-29 3 views
0

런타임에 뷰를 만들고 해당 하위 뷰로 UITableView를 추가하고 있습니다. 나는 tableview의 델리게이트를 self로 정의했다.UITableView 대리인이 호출되지 않습니다

여전히 jQuery과 대표가

@ 인터페이스의 cViewController라고하기는 아니지만 : UIViewController에

RouteShowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; 
[RouteShowView setBackgroundColor:[UIColor blueColor]]; 

table = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, 320, 410) style:UITableViewStylePlain]; 
table.delegate = self; 
UIButton * Go = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
Go.frame = CGRectMake(0, 4, 70, 42); 
[Go setTitle:@"<< BACK" forState:UIControlStateNormal]; 
[Go addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside]; 
[Go setBackgroundColor:[UIColor blackColor]]; 

[RouteShowView addSubview:table]; 
[RouteShowView addSubview:Go]; 

[self.view addSubview:RouteShowView]; 
+0

시도 [표 reloadData]; – Neo

+0

'UITableView'의'datasource'가 더 중요하기 때문에 추측하고 있습니다. 'table.datasource = self.'로 시도하고'cellForRowAtIndexPath'와'numberOfRowsInSection' 메서드를 추가하는 것을 잊지 마십시오. – iNoob

+0

또한 이것에 대해 행운이 없습니다 : ( – WakkaoW

답변

1

누락 가지

있습니다3210
//.h file 
@interface SimpleTableView : UITableView <UITableViewDelegate, UITableViewDataSource> 
{ 
} 
@end 

// in .m file 
table = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, 320, 410) style:UITableViewStylePlain]; 

// set delegated object 
table. delegate = self; 

// set source for data 
table.dataSource = self; 

그리고 jQuery과의 문서에 정의되어 @Required 프로토콜을 구현

@protocol UITableViewDataSource<NSObject> 

@required 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; 
0

을 먼저 당신이 당신의 클래스에 적절한 대표를 구입 한 경우, 엑스 코드에 코드 완성에 의한 대의원 방법을 확인해보십시오, xcode는 대리인 방법을 자동으로 감지합니다.

난 당신이

@interface SimpleTableView : UITableView <UITableViewDelegate, UITableViewDataSource> 
2

당신이 UITableViewDelegate, UITableViewDataSource 당신의 .H 파일에 추가한다고 가정 선언 할 수 없습니다 같아요 ... 난 당신이 당신의 하는 .m 파일에이 코드를 놓쳤다 생각

table.dataSource = self; 
관련 문제