2011-05-12 7 views
2

트위터, 페이스 북 및 twit pic 등의 사진을 업로드하고 싶습니다. Array에서 가져 와서 Table view에 표시했습니다. shareKit을 사용하고 있습니다. 하나의 셀을 선택한 경우 (예 : 예를 들어. Twitter) 그런 다음 트위터에 사진을 업로드하여 두 개 이상의 셀을 선택하고 하나의 버튼 (선택한 행 항목으로 보내기)에서이 작업을 수행하려고합니다. 셀을 표시/표시 해제 할 수 있지만 셀의 선택된 값을 가져 오는 방법은 없습니다. 나는다중 셀 선택 테이블 뷰

코드 ..이 테이블의 편집 모드에있을 싶지 않다 :

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


    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    if (cell.accessoryType == UITableViewCellAccessoryCheckmark) { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } 


    else { 

     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
    } 



} 
+0

중복은 달성 /stackoverflow.com/questions/308081/is-it-possible-to-configure-a-uitableview-to-allow-multiple-selection 및 http://stackoverflow.com/questions/3040894/uitableview-multiple-selection –

+0

@ IphoneDeveloper, 만약 당신이있어 정답 왜 노력하지 않았습니까? –

답변

3

sourceArray을 테이블 뷰를 채우는 데 사용하는 배열로 지정하십시오. selectedObjects은 선택되어 0 개체를 포함하도록 초기화 된 개체 배열입니다. 그것은 (개인) 클래스 인스턴스 변수 여야합니다. 사용자가 기재된 버튼의 송신 동작 방법이어서

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

    YouObjectType *object = [sourceArray objectAtIndex:indexPath.row]; //This assumes that your table has only one section and all cells are populated directly into that section from sourceArray. 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    if (cell.accessoryType == UITableViewCellAccessoryCheckmark) { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
     [selectedObjects removeObject:object]; 
    } 
    else { 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
     [selectedObjects addObject:object]; 
    } 
} 

//NSMutableArray *selectedObjects = [[NSMutableArray array] retain];

는 필요한 작업을 수행 할 selectedObjects 어레이 객체를 사용한다./:

+0

답장을 보내 주셔서 감사합니다 – iProgrammer

+0

cellforRowAtIndexPath와 함께 셀을 사용하는 것은 좋지 않습니다. 좋은 점은 모든 항목 선택 상태를 배열에 저장하고 여기에서 선택/선택을 해제하는 것입니다. 그런 다음 reloadData를 호출하십시오. –

0

당신은 셀을 선택하거나가있는 것은하는 그 배열을 관리 할 수 ​​있습니다 당신은 didSelectRowAtIndexPath 업데이트에 다음 행을 선택할 때 해당 배열을 위의 조건에 따라 배열을 사용하여 이미지를 업로드 할 때 사용하십시오. 예를 들어 - 키 @ "이미지"와 @ "isSelected"에 대한 사전 두 개의 객체가있는 배열이 있으며이 배열로 테이블을 채우고 행을 선택하면 indexPath.row에서 사전 객체로 배열의 요소에 액세스합니다. "isSelected"키에 해당 사전 "true"또는 "flase"를 업데이트하십시오.

+0

예제 나 링크를 참조 할 수 있습니까? – iProgrammer

0

didSelectRowAtIndexPath에서 indexPath.row를 가져 오면 선택한 셀을 알 수 있습니다.

1

또한 ..이 같은있는 tableview에 체크 표시를 사용하여 만들 수 있습니다

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path { 
UITableViewCell *cell = [tableView cellForRowAtIndexPath:path]; 
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) { 
cell.accessoryType = UITableViewCellAccessoryNone; 
} else { 
cell.accessoryType = UITableViewCellAccessoryCheckmark; 
} 
}