2012-01-02 8 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

... 1つのリンクが内容について説明があり ます。http: //stackoverflow.com/questions/4954393/select-multiple-rows-from-uitableview-and-delete –

答えて

3

さらにコードが複数選択を機密レベル変更の詳細についてのUITableView

#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あなたはそんなに... – Akash

+0

@ Nimit Parekh - nsuserdefaultsの複数の選択肢をnsmutablearrayに保存するにはどうすればいいですか?ありがとう:) – hanumanDev