小编use*_*021的帖子

使用UITbaleView选择一个带有一个复选标记的特定行

Plz有人告诉我如何用一个复选标记一次选择行,而其他行不是复选标记.我试过,但在我的情况下,选中带有复选标记的多行.基本上我想用选中标记保存一行,当我选择另一行然后前一行取消选择时,此行选中带复选标记.这是我的代码

    - (NSString *)getKeyForIndex:(int)index
    {
    return [NSString stringWithFormat:@"KEY%d",index];
    }
    - (BOOL) getCheckedForIndex:(int)index
    {
     if([[[NSUserDefaults standardUserDefaults] valueForKey:[self getKeyForIndex:index]]boolValue]==YES)
     {
     return YES;
     }
     else
    {
    return NO;

       } }


- (void) checkedCellAtIndex:(int)index
    {    BOOL boolChecked = [self getCheckedForIndex:index];
        [[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithBool:!boolChecked] forKey:[self getKeyForIndex:index]];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
     {
      return List.count;
    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    {
      static NSString *subviewCells = @"Cells";

       UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:subviewCells];
      if (cell == nil)
     {
      cell = [[UITableViewCell alloc] …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios xcode4 xcode5

0
推荐指数
1
解决办法
7849
查看次数

标签 统计

ios ×1

iphone ×1

objective-c ×1

xcode4 ×1

xcode5 ×1