2013-06-08 5 views
1

여기에 120 개의 단어 목록이있는 표 클래스를 만들었습니다. 이제 최소 정밀도를 위해 10 개의 행을 선택해야합니다. 내가 어떻게 테이블에서 10 개 이상의 행을 선택하고 특정 배열이나 다른 곳에 이러한 값을 저장할 수 있습니다 가이드. 날 좀 도와주세요.테이블 행에서 여러 값을 선택하고 저장하는 방법

@implementation tableview 
    NSArray *myArray ; 

- (id)initWithStyle:(UITableViewStyle)style 
{ 

    self = [super initWithStyle:style]; 

    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    myArray = [NSArray arrayWithObjects: 

       @"ad (a-d)",.......,Nil]; 

    } 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [myArray count]; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 

     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    cell.textLabel.text = [myArray objectAtIndex:indexPath.row]; //[email protected]"ASDF" works. 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; 
    [self.navigationController pushViewController:detailViewController animated:YES]; 
} 

@end 

답변

2

표에서 여러 셀을 선택하는 경우 didSelectRowAtIndexPath: 방법으로이 코드를 추가하십시오. 선택 값을 저장 들어, 바르 NSMutableArray을 만들고 행/셀을 선택할 때, 빨리, 컬렉션 객체의 값을 저장한다 마음에 와서 didSelectRowAtIndexPath:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path { 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:path]; 

    if (cell.accessoryType == UITableViewCellAccessoryCheckmark) { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } else { 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
    } 
} 
2

한 빠른 아이디어 안에 새로 선택한 개체를 추가 (배열, 사전), 계속 추가 할 수 있습니다.

행/셀 선택을 취소하면 컬렉션에서 삭제하십시오.

관련 문제