2011-05-09 2 views
2

안녕하세요 그냥 두 개의 다른 사용자 정의 uitableviewcells 내 uitableview에 두 개의 다른 섹션으로로드하는 방법을 알아 내려고 ... 단지 진행 방법에 대한 확실하지 ... 여기에 현재 코드가두 개의 사용자 정의 uitableviewcells를 반환하는 방법

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 2; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 1; 
} 

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

    //Registration Button 
    static NSString *CellIdentifier = @"CustomRegCell"; 
    static NSString *CellNib = @"LogInCustomCell"; 

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil]; 
     cell = (UITableViewCell *)[nib objectAtIndex:0]; 
    } 
    return cell; 

} 

/////// NEW ATTEMPT .... :(

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 2; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 1; 
} 

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

    if (indexPath.section == 0) 
    { 
     //Registration Button 
     static NSString *CellIdentifier = @"CustomRegCell"; 
     static NSString *CellNib = @"LogInCustomCell"; 

     UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil]; 
      cell = (UITableViewCell *)[nib objectAtIndex:0]; 
     } 
     return cell;   

    } 
    else if (indexPath.section == 1) 
    { 
     //Registration Button 
     static NSString *CellButtonIdentifier = @"CustomButtonCell"; 
     static NSString *CellButtonNib = @"LogInCustomCell"; 

     UITableViewCell *cellButton = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellButtonIdentifier]; 
     if (cellButton == nil) { 
      NSArray *nibButton = [[NSBundle mainBundle] loadNibNamed:CellButtonNib owner:self options:nil]; 
      cellButton = (UITableViewCell *)[nibButton objectAtIndex:0]; 
     } 
     return cellButton;  

    } 
    return nil; 

} 

답변

3

indexPath 변수의 section 속성을 사용하여 당신이 그 부를 수 ... 경우 :

섹션 번호는 나타나는 순서에 따라 달라집니다. tableView에 표시하려는 첫 번째 섹션은 0 등이됩니다.

+0

맞아요. 만약에 .. 만약에 ..하려고하면, 그랬어. 그리고 내가로드하려고 할 때 화면이 부서져 버렸어 .. – tinhead

+0

그럼 아마 기대하지 않았던 세번째 부분이 있었을거야. 나는 그 메소드가 무효 셀을 반환 할 수 없다는 에러를 받았다고 내기를 기꺼이합니다. 충돌을 게시 할 수 있습니까? –

+0

솔직히 나는 그것을 쓰는 법을 모른다. 그래서 그 오류를 알지 못한다. 나는 내가 한 짓으로 내 코드를 업데이트 할 것이다. 그것도 나에게 오류를주지는 않지만 그것도 다른 사용자 정의 uitableviewcell을 표시하지 않는다 ... 나는 가지고있다. 하루 종일이 일을하고 있었고, 뇌진탕이었습니다. 이제는 코드를 업데이트 할 수없는 것 같습니다. – tinhead

관련 문제