Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在UITableview中选择多行_Iphone_Cocoa Touch - Fatal编程技术网

Iphone 如何在UITableview中选择多行

Iphone 如何在UITableview中选择多行,iphone,cocoa-touch,Iphone,Cocoa Touch,我想在UITableview中选择多行。我可以选择,但问题是当我滚动UITableView时,会自动选择特定行。 我正在使用以下代码: -(void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; if

我想在
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];


    }

}

你可以看看下面的文章。

更多代码用于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

有关重新分级多个选择的更多详细信息,请参阅

有一个关于内容的链接。。嘿,伙计……千载难逢……你为我节省了很多时间……非常感谢……@Nimit Parekh-你如何将多个选择存储到nsuserdefaults中的nsmutablearray中?谢谢:)