2016-10-05 1 views
1

안녕하십니까. UIViewController에 2 UITableviews (tableview1 및 tableview2)이 있습니다. 이미 MVC 메서드를 사용하여 tableview1에 일부 배열을로드했지만 tableview2는 비어 있습니다. 어쨌든 아래의 UI에 따라 추가 버튼을 누르거나 UILongpressgesture을 사용하여 tableview1 선택한 셀을 tableview2로 드래그하여 tableview1에서 tableview2로 선택된 행을로드해야합니다.동일한 uitableviewcontroller에있는 빈 uitableview 셀에 여러 개의 선택된 uitableviewcell을 추가하는 방법

screen shot

는 사람은 나에게 관련 아이폰 OS (objective-c) 자습서, 지침 또는 몇 가지 아이디어를 얻을 수있는 샘플 프로젝트 저장소에 대한 링크를 제공 할 수 있습니다.

이것은 I마다 사용자가 셀을 선택/클릭 별도의 배열로 선택된 행의 데이터를 추가 TableView1

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    tableView1.dataSource =self; 
    tableView2.delegate=self; 
    tableView2.dataSource=self; 
    tableView2.delegate=self; 
    self.cellSelected=[NSMutableArray array]; 




    //Personal Assigned Array 
    SAassigned *psaUser1=[SAassigned new]; 
    [email protected]"Peter Parker"; 
    [email protected]"men1.jpg"; 

    SAassigned *psaUser2=[SAassigned new]; 
    [email protected]"Michel Jordan"; 
    [email protected]"men2.jpg"; 

    SAassigned *psaUser3=[SAassigned new]; 
    [email protected]"Tiego Costa"; 
    [email protected]"men3.jpg"; 

    SAassigned *psaUser4=[SAassigned new]; 
    [email protected]"Ketty perry"; 
    [email protected]"women1.jpg"; 

    SAassigned *psaUser5=[SAassigned new]; 
    [email protected]"Jimmy More"; 
    [email protected]"men1.jpg"; 

    SAassigned *psaUser6=[SAassigned new]; 
    [email protected]"James Franklin"; 
    [email protected]"men2.jpg"; 

    SAassigned *psaUser7=[SAassigned new]; 
    [email protected]"Peter Parker"; 
    [email protected]"men3.jpg"; 

    SAassigned *psaUser8=[SAassigned new]; 
    [email protected]"Jessica Helan"; 
    [email protected]"women1.jpg"; 

    assignedUsers=[NSMutableArray arrayWithObjects:psaUser1,psaUser2,psaUser3,psaUser4,psaUser5,psaUser6,psaUser7,psaUser8, nil]; 

    } 

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



     //tableView 1 
     PACell *cell=[tableView dequeueReusableCellWithIdentifier:@"pCell"]; 

     if([self.cellSelected containsObject:indexPath]) 
     { 
      cell.accessoryType = UITableViewCellAccessoryCheckmark; 

     } 
     else 
     { 
      cell.accessoryType=UITableViewCellAccessoryNone; 
     } 

     if (cell==nil) { 

      cell=[[PACell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"pCell"]; 
     } 

     //tableview 2 
     PSCell *cell2=[tableView dequeueReusableCellWithIdentifier:@"pCell2"]; 
     if([self.cellSelected containsObject:indexPath]) 
     { 
      cell2.accessoryType = UITableViewCellAccessoryCheckmark; 

     } 
     else 
     { 
      cell2.accessoryType=UITableViewCellAccessoryNone; 
     } 

     if (cell2==nil) { 

      cell2=[[PSCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"pCell2"]; 
     } 

     SAassigned *assigned=nil; 

     if(tableView == self.tableView1) 
     { 
      assigned=[assignedUsers objectAtIndex:indexPath.row]; 
      cell.persName.text=assigned.psaName; 
      cell.persImage.image=[UIImage imageNamed:assigned.psaimage]; 
     } 
     else if(tableView == self.tableView2) 
     { 
      // not yet implemented/loaded - empty 
      return cell2; 
     } 
     return cell; 
} 

답변

0

에 데이터를 로딩하는 방법이다. 선택한 데이터를 다른 셀에 표시하는 동안 해당 배열을 사용하여로드하십시오.

+0

일부 코드는 도움이됩니다. 테이블 뷰 1과'cellForRowAt ....'및'didSelectRow..' 코드에서 데이터를로드하기 위해 어떤 배열을 사용하고 있는지. –

+0

요청한 코드를 추가했습니다. 미리 감사드립니다. – Fido

0

인스턴스 배열 객체를 만들어야합니다.

NSMutableArray *selectedArray = [NSMutableArray alloc]init]; 

"chooseArray"에서 개체를 추가하거나 제거해야합니다.

if (cell.accessoryType == UITableViewCellAccessoryCheckmark) { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
     [selectedArray removeAtIndex:indexPath.row] 
    } else { 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
     [selectedArray insertObject:yourObject atIndex:indexPath];.row] 
    } 
관련 문제