2014-02-06 2 views
0
- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *CI= @"GenusNameCell"; 

    GenusNameCell *cell = [tableView dequeueReusableCellWithIdentifier:CI]; 
    if (cell == nil) { 
     cell = [[GenusNameCell alloc] initWithStyle:UITableViewCellStyleDefault 
            reuseIdentifier:@"GenusNameCell"]; 

     [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; 
    } 
    int row = [indexPath row]; 

    cell.GenusNameLabel.text = [genusName objectAtIndex:indexPath.row]; 
    cell.GenusCommonNameLabel.text = _genusCommonName[row]; 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    SpeciesViewController *Species = [[SpeciesViewController alloc] initWithNibName:@"SpeciesViewController" bundle:nil]; 
    if ([[genusName objectAtIndex:indexPath.row] isEqual:@"Abelia"]) { 
     Species.SpeciesInt = 0; 
     [Species setTitle:[genusName objectAtIndex:indexPath.row]]; 
    } 
} 

연결하려면 2 개의 tableviews가 있지만이 코드와 함께 할 것인지 잘 모르겠습니다. 그것은 내가 충돌 셀을 클릭하면 실행됩니다. 누군가 나를 도울 수 있습니까?tableview에서 tableview로 푸는 방법

+3

그렇다면 왜이 코드를 포함하고'didSelectRowAtIndexPath : ... '의 코드가 아닌가? –

+1

가 구현 한 - (무효)있는 tableView : (jQuery과 *)있는 tableView didSelectRowAtIndexPath : (NSIndexPath *) indexPath – Jared

+0

- (무효)있는 tableView : (jQuery과 *)있는 tableView didSelectRowAtIndexPath : (NSIndexPath *) indexPath { SpeciesViewController * 종 = [ [SpeciesViewController alloc] initWithNibName : @ "SpeciesViewController"번들 : nil]; if ([[genusName objectAtIndex : indexPath.row] isEqual : @ "Abelia"]) { Species.SpeciesInt = 0; [Species setTitle : [genusName objectAtIndex : indexPath.row]]; } – user3228210

답변

0

스토리 보드 또는 펜촉을 사용하고 있습니까?

storyboard를 사용하는 경우 prepareForSegue를 구현해야하지만 nibs를 사용하는 경우 새보기 컨트롤러를 didSelectRowAtIndexPath의 스택으로 푸시해야합니다.

+0

@ user3228210 평판이 50이 아니므로 위의 내용을 추가 할 수 없으므로 잘 보시면 알 수 있습니다. 스토리 보드와 모델이 어떻게 구성되어 있는지 보지 않고도 정확히 무엇이 잘못되었는지 말할 수 있습니다. 프로젝트의 압축 버전에 대한 링크를 제공 할 수 있습니까? – Nick

1

셀을 선택하면 새 VC가 만들어 지지만 절대로 제공되지 않습니다.

[self.navigationController pushViewController:Species animated:YES]; 

을 사용하십시오.

또한 Ctrl 키 (스토리 보드)에 두 번째 VC에 대한 첫 번째 VC 세포로부터이 코드를 사용할 수 있습니다

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if ([segue.identifier isEqualToString:@"nameOfYourSegue"]) { 
     if ([[segue destinationViewController] isKindOfClass:[SpeciesViewController class]]) { 
      SpeciesViewController *Species = (SpeciesViewController *)[segue destinationViewController]; 
     Species.SpeciesInt = 0; 
     [Species setTitle:[genusName objectAtIndex:indexPath.row]]; 
     } 
} 

스토리 보드에 segueIdentifier을 설정하는 것을 잊지 마십시오!

+0

코드의 맨 위 부분은 있지만 prepareForSegue 메서드는 cellForRowAtIndexPath 또는 didSelectRowAtIndex에 삽입합니까? – user3228210

+0

segue가 수행되기 전에 prepareForSegue가 자동으로 호출되므로 다른 메소드와 마찬가지로 구현 파일에 넣기 만하면됩니다. 응용 프로그램이 충돌 할 때 어떤 오류 메시지가 나타 납니까? – Jorn

+0

나는 prepareForSegue 메서드를 넣는다. 충돌없이 작동하지만 셀을 클릭하면 다음 tableview로 이동하여 배열 1 개를로드하지만 3 개의 다른 배열을 가지고 있어도 모든 셀에 대해 동일한 배열을로드한다. – user3228210

관련 문제