2012-01-13 2 views
0

json webservice url로 채워진 표보기가 있습니다. 눈금 표시에 "UITableViewCellAccessoryCheckmark"를 사용하고 있습니다. 사용자가 여러 테이블 뷰를 선택하면 모든 선택된 행 데이터가 단일 변수에 저장되기를 원합니다. 사람들이 나를 도와 줄 수 있습니까? 아래는 코드입니다. 당신은 다중 선택을 설정 한 경우NSString에서 검사 된 행의 값을 저장하는 방법

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


static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 

} 

if ([self.arForIPs containsObject:indexPath]) { 
    [cell setAccessoryType:UITableViewCellAccessoryCheckmark]; 
} 
else { 
    [cell setAccessoryType:UITableViewCellAccessoryNone]; 
} 


NSString *imagefile1 = [media1 objectAtIndex:indexPath.row]; 


cell.textLabel.text=[story objectAtIndex:indexPath.row]; 

cell.detailTextLabel.text=[descriptiondesc objectAtIndex:indexPath.row]; 

cell.detailTextLabel.numberOfLines=2; 
//cell.detailTextLabel.backgroundColor=[UIColor clearColor]; 

img=[UIImage imageNamed:@"icon.png"]; 
cell.imageView.image=img; 

NSLog(@"BOOMMMM:%@",pileup); 
return cell; 
} 

enter image description here

답변

3

당신이 선택한 행의 모든 ​​인덱스를 얻기 위해 jQuery과의 indexPathsForSelectedRows을 사용할 수 있어야합니다. 이를 통해 서버에서 다운로드 한 원본 데이터를 다시 참조하고 필요한 문자열을 얻을 수 있습니다.

tableView:didSelectRowAtIndexPath: 범위 내에서 사용하면 현재 선택된 모든 행의 문자열을 작성할 수 있습니다.

EDIT : 관련된 데이터 몇 개를 함께 저장하려면 NSDictionary (또는 생성 후 편집해야 할 경우 NSMutableDictionary)를 사용할 수 있습니다. 코드에 대한 예를 들어, 한 행에 대한 모든 데이터를 저장하기 :

NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:3]; 
[dict setObject:[media1 objectAtIndex:indexPath.row] forKey:@"image"]; 
[dict setObject:[story objectAtIndex:indexPath.row] forKey:@"story"]; 
[dict setObject:[descriptiondesc objectAtIndex:indexPath.row] forKey:@"desc"]; 

또는 직선 정기적있는 NSDictionary로를 만들 수 있습니다 여기를 참조 : http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsdictionary_Class/Reference/Reference.html

+0

씹는 담배의 한 조각이 유 저장하는 방법의 예를 내놔 하나의 변수에서 thecheck 행의 데이터를 시도했지만 unsucessful했습니다 – kingston

+0

행 당 하나의 개체에 물건을 저장할 수있는 몇 가지 코드를 추가했습니다. –

+0

@PhilippeSabourin : 나는 또한 같은 방식으로 구현했습니다. :) – Sarah

관련 문제