当前位置:数据库 > Access >>

ios 关于UITableView UITableViewCellAccessoryCheckmark 混乱的问题

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
    }

 

 

可在单击记录的方法里记录下选择的记录:

 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {//table单击事件
    UITableViewCell *cell = [tableView cellForRowAtIndexPath: indexPath];
    NSString *str=cell.textLabel.text;
    NSDictionary *dict=[self getOneDictByName:str];
    if([self isExistsByName:str theArray:selectedData]){
        [self removeOneFromArrayByName:str theArray:selectedData];
    }else{
        [selectedData addObject:dict];
    }
    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

}

代码中的selectedData是一个NSMutableArray。

然后在cellForRowAtIndexPath方法里限定cell的accessoryType值。

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellStr= @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
    }
    NSArray *keys=[tempResult allKeys];
    NSArray *dicts= [tempResult valueForKey:[keys objectAtIndex:indexPath.section]];
    NSDictionary *temp=[dicts objectAtIndex:indexPath.row];
    cell.textLabel.text=[temp valueForKey:@"name"];
    if([selectedData containsObject:temp]){
        cell.accessoryType=UITableViewCellAccessoryCheckmark;
    }else{
        cell.accessoryType=UITableViewCellAccessoryNone;
    }
    return cell;
}

上面的if  else  要完整。

其实思想就是MVC,视图只是用来展示,到底展示什么取决于model;

 

 

 

补充:移动开发 , IOS ,
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,