2012-01-02 2 views
2

UITableview에서 여러 행을 선택하고 싶습니다. 내가 선택할 수 있지만 내 문제는 내가 스크롤했을 때 특정 행의 자동 선택이 있습니다 UITableView입니다. 이 코드를 사용하고 있습니다 :UITableview에서 여러 행을 선택하는 방법

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

    if ([selectedCell accessoryType] == UITableViewCellAccessoryNone) { 
     [selectedCell setAccessoryType:UITableViewCellAccessoryCheckmark]; 


    } 
    else { 
     [selectedCell setAccessoryType:UITableViewCellAccessoryNone]; 


    } 

} 
+0

.. 하나 개의 링크 콘텐츠에 대한 설명이 HTTP : //stackoverflow.com/questions/4954393/select-multiple-rows-from-uitableview-and-delete –

답변

3

또한 코드는 다중 선택을 regrading 자세한 내용은 jQuery과

#import "RootViewController.h" 

@implementation RootViewController 

@synthesize arForTable = _arForTable; 
@synthesize arForIPs = _arForIPs; 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.arForTable=[NSArray arrayWithObjects:@"Object-One",@"Object-Two",@"Object-Three",@"Object-Four",@"Object-Five", nil]; 
    self.arForIPs=[NSMutableArray array]; 
} 

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

- (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] autorelease]; 
    } 
    if([self.arForIPs containsObject:indexPath]){ 
     [cell setAccessoryType:UITableViewCellAccessoryCheckmark]; 
    } else { 
     [cell setAccessoryType:UITableViewCellAccessoryNone]; 
    } 
    cell.textLabel.text=[self.arForTable objectAtIndex:indexPath.row]; 
    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    if([self.arForIPs containsObject:indexPath]){ 
     [self.arForIPs removeObject:indexPath]; 
    } else { 
     [self.arForIPs addObject:indexPath]; 
    } 
    [tableView reloadData]; 
} 

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

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



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

@end 

에서 다중 선택에 사용하는 것입니다 참조하십시오 following link here.

+1

헤이 버디 ...... 천 시간 고맙습니다 .... 내 많은 시간을 절약 할 수 있습니다. k so so much ... – Akash

+0

@ Nimit Parekh - nsperfaults에 nsmutablearray에 여러 선택 사항을 저장하는 방법은 무엇입니까? 감사 :) – hanumanDev

관련 문제