2013-02-11 5 views
1

현재 테이블 뷰가있는 앱을 만드는 중입니다. 제가보기에 첫 번째 행을 클릭하면 view1이 표시되고 두 번째 행을 클릭하면 view2가 표시됩니다. 내가 어떻게 할 수 있니? 테이블 뷰는 클릭 한 행에 따라 다른 뷰를 엽니 다.

가 나는 경우 else 문 ID를 사용하려고 내 didSelectRowAtIndexPath하지만 코드의 내 작품은 여기에 작동하지 않았다

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

int EntryIndex = [indexPath indexAtPosition:[indexPath length]-1]; 

{ 
    AboutViewController *aboutView = [[AboutViewController alloc]init]; 
    aboutView.getId4 = [[contentArray objectAtIndex:EntryIndex]objectForKey:@"title"]; 
    aboutView.aboutofficeId = getId3; 
    [self.navigationController pushViewController:aboutView animated:YES]; 
} 
else 
{ 
    DepartmentsViewController *deptView = [[DepartmentsViewController alloc]init]; 
    deptView.getId5 = [[contentArray objectAtIndex:EntryIndex]objectForKey:@"title"]; 
    deptView.deptoffice = getId3; 
    [self.navigationController pushViewController:deptView animated:YES]; 
} 

} 
+0

U 내가 새로운있는 UIViewController를 추가 할 UIView의 또는있는 UIViewController >> – iPatel

+0

을 추가 WNT :) –

답변

0

참고 : UIView의를 생성하고 표시 할, 그래서 여기에 UIView을하지 퍼트 UIViewController.

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 

     if(indexPath.row == 1) 
     { 
      UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake("AsYouWnat")]; 
      view1.backgroundColor = [UIColor redColor]; 
      [self.view addSubview:view1]; 
     } 
     else if(indexPath.row == 2) 
     { 
      UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake("AsYouWnat")]; 
      view2.backgroundColor = [UIColor redColor]; 
      [self.view addSubview:view2]; 
     } 
     . 
     . 
     . 
     . 
     . 
     ////////// As Your Row In Table 
     else 
     { 
      UIView *viewN = [[UIView alloc] initWithFrame:CGRectMake("AsYouWnat")]; 
      viewN.backgroundColor = [UIColor redColor]; 
      [self.view addSubview:viewN]; 
     } 
    } 
+0

다른 UIViewcontroller를 어떻게 표시 할 수 있는지 보여 줄 수 있습니까? –

+1

간단한 UIView의 ViewController 인스턴스를 만듭니다. :) AboutViewController * aboutView = [[AboutViewViewroller alloc] init]와 같은 것; aboutView.getId4 = [[contentArray objectAtIndex : EntryIndex] objectForKey : @ "title"]; aboutView.aboutofficeId = getId3; [self.navigationController pushViewController : aboutView animated : YES]; – iPatel

+0

감사! 이것은 지금 할 것이다 :) –

0
  1. 당신은 당신이 변경 가능한 배열을 선언하고 UIView의 내용이 콘텐츠 스타일의 다른 종류가있는 경우 그에 UIviews을 추가 할 수있는 뷰를 표시하고자하는 경우 .

  2. 동일한 스타일의보기를 표시해야하지만 내용 만 다릅니다. 다음 코드를 검색 할 수 있습니다. 그런 다음 다른 ViewControllers을 표시 할 경우

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,460)]; 
    switch (indexPath.row) { 
    case 0: 
    { 
    //Add your label,image,etc 
    [self.view addSubview:view]; 
    } 
        break; 
    
        case 1: 
    { 
    
    //Add your label,image,etc 
    [self.view addSubview:view]; 
    
    } 
        break; 
    
  3. 이 유 코드 다음을 수행 할 필요가

    #import "ViewController1.h" 
    #import "ViewController2.h" 
    #import "ViewController3.h" 
    
    -(void)viewDidLoad 
    { 
    
    VCArray=[[NSMutableArray alloc]initWithObjects:ViewController1,ViewController2,ViewController3];//allocate and init ViewController and add that to VCArray 
    
    } 
    
    
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    
    UIViewController *viewcontr=[VCArray objectAtIndex:indexpath.row]; 
    viewcontr=[[viewcontr alloc]init]; 
    [self presentModalViewController:viewcontr animated:YES]; 
    
        } 
    
+0

thanks! 제 3 회 대답을 사용하고 있지만 오류가 발생했습니다. [__NSCFConstantString parentViewController] : 알 수없는 선택기가 인스턴스 0x1ab7c에 전송되었습니다. –

+0

감사합니다! 임 당신의 3 번 응답을 사용하지만 오류 [__NSCFConstantString parentViewController] 점점 메신저 : u는 당신이 배열 –

+0

로 전송을 - (무효)은 { [슈퍼 viewDidLoad에 viewDidLoad]; VCArray = [[NSMutableArray alloc] initWithObjects : @ "AboutViewController", @ "DepartmentsViewController", nil]; if ([contentArray count] == ​​0) { [self grabXML]; [contentTable reloadData]; [__NSCFConstantString ALLOC] :의 TBT lionArmanCapistrano 나는이 오류가있어 3 옵션 – Dany

관련 문제