2014-04-25 3 views
0

하나를 복수 UIViewControllers에 사용할 수 있습니까? 그렇다면 어떻게 가능합니까? 미리 감사드립니다.여러 UIViewController에서 하나의 UITableViewController

UITablewView 인 동일한 레이아웃의 화면 (UIViewControllers)이 있습니다. 따라서, 모든 화면에 대해 UITableViewController 하나를 만들 수 있으며 모든 화면에서 사용할 수 있습니까? (UIViewControllers). 그렇다면 사용자 정의 셀을 사용할 필요가 없으며 사용자 지정 셀을 사용할 필요가 없습니다.

+0

같이있는 tableview에

추가 태그를 도움이되기를 바랍니다. 다른 셀을 사용하고 싶다면,'cellForRowAtIndexPath : – Akhilrajtr

답변

0

동일한 대리자 및 데이터 소스 메서드를 두 번 구현하지 않으려면 하나의 컨트롤러에서 수행하고 다른 멤버를 하위 클래스로 하위 클래스로 만듭니다.

0

UITableViewController이 실제로 무엇인지 완전히 이해하지 못하는 것 같습니다. 그것은 실제로 하위 클래스 UIViewController입니다.

UIViewControllers에는 UITableViewController이 필요 없습니다. UIViewController을 사용하려면 UITableView을 수동으로 구현해야합니다.

tableView에 설정된 대리자 및 데이터 소스가 필요하다고 생각하면 동일한 tableView를 많은 ViewController와 재사용하기가 다소 복잡 할 수 있습니다. 이 작업을 별도의 클래스 또는 핫 스왑에 제공하면 만족스럽지 않은 경우입니다.

0

예, 가능하지만 uiitableview를 3 개의 모든 viewcontroller에 추가해야했습니다.

여기 몇 가지 예 ..! 21

enter image description here

로하고있는 tableview 구현 파일이있는 tableview에 enter image description here 세트 태그이

@implementation LCsampleTableView 

     UITableView *tableView1; 
- (id)initWithCoder:(NSCoder *)aDecoder { 

    // self = [super init]; 
    self = [super initWithCoder:aDecoder]; 

    if (self) { 

     tableView1 =(UITableView *)[self viewWithTag:21]; 
     [tableView1 setDelegate:self]; 
     [tableView1 setDataSource:self]; 


     //  [self myviewDidload]; 

    } 

    return self; 
} 

#pragma mark - Table view start 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 2; 

} 




-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tblCell"]; 



    //cell = myCellDeque; 
    if(cell == nil){ 
     //  cell = myCellDeque; 

     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"tblCell"]; 

     UILabel *lb1 = [[UILabel alloc] initWithFrame:CGRectMake(25, 6, 154, 20)]; 
     lb1.tag = 1; // Set a constant for this 
     lb1.font = [UIFont systemFontOfSize:9.0]; 
     [lb1 setTextColor:[UIColor whiteColor]]; 
     lb1.backgroundColor = [UIColor clearColor]; 

       cell.contentView.backgroundColor= [UIColor colorWithRed:7.0/255.0 green:91.0/255.0 blue:164.0/255.0 alpha:1] ; 

     [cell.contentView addSubview:lb1]; 


    } 


    return cell; 
} 


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






} 



#pragma -mark tableDelete 

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    //Return YES if you want the specified item to be editable. 
    return YES; 
} 

// Override to support editing the table view. 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 










} 



@end 

처럼 구현은 다음 세 가지 컨트롤러에서 클래스와이있는 tableview를 추가 할 경우에 있었다 해달라고 3 개의 모든 컨트롤러에서이 tableview에 대한 코드. 그것은 당신이 데이터에 따라 서로 다른 데이터 소스를 표시하기와 같은`UITableViewController`을 사용할 수 있습니다이 enter image description here

+0

'에서이 작업을 수행 할 수 있습니다. viewWithTag 메소드는 어디에 있습니까? 그리고 viewWithTag 메소드와 함께해야 할 일은 – Vishnu

+0

입니다.이 LCsampleTableView 클래스는 메소드 뷰를 가져 오는 것보다 uiview의 서브 클래스 여야합니다. – shujatAli

+0

행을 선택한 후 여기에 상황이 있습니다. 다른 viewcontroller로 이동해야하는 – Vishnu

관련 문제