2011-10-17 9 views
0

가 나는의 ViewController를 가지고 있고, 위임 UITableViewDelegate 및 UITableViewDataSource를 구현라고, 그래서 나는 방법에 따라 결코 : 나는 각 방법에 대한 중단 점을 설정 있는 tableview 위임 방법은

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return [_nameArray count]; 
} 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    return 50; 
} 
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ 
    return @"name"; 
} 
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *TableIdentifier = @"TableIdentifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableIdentifier]autorelease]; 
    } 
    UILabel *nameLabel = [[UILabel alloc] init]; 
    nameLabel.textAlignment = UITextAlignmentLeft;  
    nameLabel.text = @"100"; 
    nameLabel.backgroundColor = [UIColor blackColor]; 
    nameLabel.textColor = [UIColor yellowColor]; 
    [cell.contentView addSubview:nameLabel]; 
    [nameLabel release]; 
    return cell; 
} 

, 내가 찾을 수

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

은 호출되지 않았지만 다른 두 메소드를 호출 할 수 있습니다. 그래서 뭐가 문제 야? 고맙습니다.

갱신 :

내가 IB에의 소유자를 제출 datasoucre 및 대리자를 연결,하지만 문제를 해결할 수 없습니다.

+0

IB를 사용하고 있습니까? dataSource를 연결하고 IB의 속성을 위임 했습니까? 아니면 사용하지 않을 경우 코드에서 위임을 수행 했습니까? –

+0

numberOfRowsInSection 메서드의 배열 수가 0보다 큰지 확인하십시오. –

+0

네, 맞습니다. 내 질문에 대답하면 ... 동의합니다. – Gaojian922188

답변

5

을 사용하기 때문에 _nameArray 난 경우 nil 또는 0 객체 delegate 메소드 numberOfRowsInSection은 0을 반환하며 위에서 언급 한 두 가지 메소드 모두에 포함되지 않습니다.

빠른 검사를 위해 numberOfRowsInSection 메서드에서 harcoded 값을 10으로 반환 한 다음 cellForRowAtIndexPath 메서드를 호출 할 수 있습니다.

3

테이블 뷰를 코드 또는 인터페이스 작성기 콘센트를 통해 대리인에 연결했는지 확인하십시오.

+0

이 저에게 효과적입니다. 루키 실수. :) – RainCast

0

클래스에 tableView 대리인을 설정 했습니까? 당신이있는 UITableViewController를 서브 클래스하지 않는 한

또한, 당신은 또한 구현해야

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; 
12

대부분의 가능성이 있기 때문에 위임 참조 문제 ..에 .. 당신이 준 적절한 참조 방법을 위임

을 그 코드가 cellForRowAtIndexPath 오는 아니에요 이유 0 개체가 _nameArray이 두 줄

self.tableView.delegate = self; 
self.tableView.dataSource = self; 
0

모든 대리인과 모두를 설정 한 경우 문제는 셀 크기보다 작은 UITableview의 크기 일 수 있습니다.

2

나는 비슷한 문제에 직면 해있다. 데이터 소스가 작동했지만 대리인이 아니 었습니다. "UITapGestureRecognizer"를 "self.view"에 추가하면 문제가 발생합니다. 이 경우 사용자 상호 작용과 관련된 테이블 위임은 호출되지 않습니다. 사용자 상호 작용이 발생할 때 "didSelect"와 같은 대리자가 호출되기 때문입니다. 이 경우보기에 UITapGestureRecognizer가 있으면 테이블 위임이 작동하지 않습니다.