开发者

how to check the contents of a table view for checked items?

I want to be able to check开发者_JAVA技巧 which items in my table view contain a check and then being able to sort the results. The items that are loaded into the array are from an NSArray.


You need to pars all the cells and see if

cell.accessoryType == UITableViewCellAccessoryCheckmark;

Or you can map checked cells in other array.


For this there is a simple solution just add dictionary on each index of the array. Now what the dictionary will contain is you text that your Array is having with key and secondly another key will have the status yes/no whether it is checked or not.

//Add Dictionary to array

                    NSMutableDictionary *dForCell=[NSMutableDictionary alloc]init];

        [dForCell setObject:Text forKey:@"Text"];
        [dForCell setObject:yes/no forKey:@"status"];
        [resultArray addObject:dForCell];
        dForCell=nil;
        [dForCell release];

Now access the dictionary based on index.

//Get the Dictionary

NSMutableDictionary *dd=(NSMutableDictionary *)[self.YourArray objectAtIndex:indexPath.row]; NSlog("%@",[dd valueForkey:@"Text"]); NSlog(%@),[dd valueForkey:@"status"]); & check the condition as per your requirements.


You can use accessory type of UITableViewCell to check if the cell has a tick mark

if(cell.accessoryType == UITableViewCellAccessoryCheckmark)

 {
  // do something

 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜