i have an array of objects which i am populating in a UItable one of my attributes of each object is a YES/NO value
Im using the- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { to populate my table as follows .
My code creates a table entry for each object in the array. I would like to only populate the table using objects in the array which have the “display” attribute set to YES? how do i do this?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellidentifier = @"customcell";
customcell *cell = (customcell *)[tableView dequeueReusableCellWithIdentifier:
cellidentifier];
my_details *myObj = [appDelegate.myArray objectAtIndex:indexPath.row];
// UITableViewCell cell needs creating for this UITableView row.
if (cell == nil)
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"customcell" owner:self options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[customcell class]]) {
cell = (customcell *) currentObject;
break;
}
}
}
cell.line1.text = myObj.line1;
cell.line2.text = myObj.line2;
cell.line3.text = myObj.line3;
return cell;
}
It would be a good idea to try to filter the objects before sending them to the table for display.
You could use an NSPredicate to filter the array of objects and when an object changes it’s state, the display attribute is set to yes, refilter the array and pass it to the tableview.
after you obtain the filteredArray you need to pass it to the tableView and tell it to reload it’s data in order to refresh.