Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8490253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:03:53+00:00 2026-06-10T22:03:53+00:00

I have a mutable Array in a Tableview, this is populated on View did

  • 0

I have a mutable Array in a Tableview, this is populated on View did load from an SQLite database, However this database changes as it is a favourites database for products in my app.
When a user selects one of the items in the tableview (The user then goes to a detail view, with the info from the database) the user can then select to remove it from the favourites (database) when the user then presses back in the navigation bar, the item is still there, I’ve tried tableview reload on view did appear, and view will appear but that doesn’t help,

Can anyone shed any light on this??

Many thanks,
Andrew

Here is my code:
FavTableViewController.h:

@interface FavTableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *Table; 
}
@property (nonatomic, strong) UITableView *Table;
@property (nonatomic, strong) NSArray *cats;
@property (nonatomic, strong) IBOutlet UISearchBar *searchBar;
@property (nonatomic, strong) UISearchDisplayController *searchDisplayController;
@property (nonatomic, strong) NSMutableArray *filteredListContent;
@property (nonatomic, strong) NSMutableArray *listContent;
@property (nonatomic, strong) NSArray *everything;
@property (nonatomic, copy) NSString *savedSearchTerm;
@property (nonatomic) NSInteger savedScopeButtonIndex;
@property (nonatomic) BOOL searchWasActive;
@property (nonatomic, strong) NSString *cellText;
-(void) refresh;
@end

FavTableViewController.m:

#import "FavTableViewController.h"
#import "DBFavAdapter.h"
#import "MenuData.h"
#import "DBAdapter.h"
#import "DetailViewController.h"
#import "ConsoleDetailController.h"
#import "EffectDetailViewController.h"
#import "DimmersDetailController.h"
#import "ConventionalController.h"
#import "ProDetailViewController.h"


@implementation FavTableViewController

@synthesize filteredListContent, savedSearchTerm, savedScopeButtonIndex, searchWasActive, searchBar, searchDisplayController, listContent, everything, cellText, cats, Table;

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    listContent = [[NSMutableArray alloc] init];
}
return self;
}

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad {
NSLog(@"Did Load");
[super viewDidLoad];

everything = [[DBFavAdapter allProducts] mutableCopy];
for (NSDictionary *dict in everything) {
    [listContent addObject: [dict objectForKey:@"Title"]];
}



// create a filtered list that will contain products for the search results table.

self.filteredListContent = [NSMutableArray arrayWithCapacity:[self.listContent count]];

// restore search settings if they were saved in didReceiveMemoryWarning.
if (self.savedSearchTerm)
{
    [self.searchDisplayController setActive:self.searchWasActive];
    [self.searchDisplayController.searchBar setSelectedScopeButtonIndex:self.savedScopeButtonIndex];
    [self.searchDisplayController.searchBar setText:savedSearchTerm];

    self.savedSearchTerm = nil;
}
//  [self.tableView reloadData];
self.Table.scrollEnabled = YES;
self.navigationItem.title = @"Favourites";
//  cats = [DBFavAdapter allCategories];
}

- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.filteredListContent = nil;
NSLog(@"Unload");
}

- (void)viewWillAppear:(BOOL)animated {
NSLog(@"View will Appear");

[Table reloadData];
NSLog(@"Everything: %@",everything);
NSLog(@"list Content: %@",listContent);
[super viewWillAppear:animated];  
}

- (void)viewDidAppear:(BOOL)animated {
NSLog(@"View did Appear");
[super viewDidAppear:animated];
NSLog(@"list Content appeared: %@",listContent);
[Table reloadData];
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
NSLog(@"Did dissapear");
// save the state of the search UI so that it can be restored if the view is re-created
self.searchWasActive = [self.searchDisplayController isActive];
self.savedSearchTerm = [self.searchDisplayController.searchBar text];
self.savedScopeButtonIndex = [self.searchDisplayController.searchBar selectedScopeButtonIndex];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(tableView == self.searchDisplayController.searchResultsTableView){
    return [self.filteredListContent count];
}
else {
    return [self.listContent count];
}
NSLog(@"Rows %i",[self.listContent count]);
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {    
//    NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
if (tableView == searchDisplayController.searchResultsTableView)
{
    cellText = [self.filteredListContent objectAtIndex:indexPath.row];
}
else
{
    cellText = [self.listContent objectAtIndex:indexPath.row];
}


// NSString *cellText = [self.listContent objectAtIndex:indexPath.row];
UIFont *cellFont = [UIFont fontWithName:@"Heiti TC" size:17.0];
CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];

return labelSize.height + 30;
}
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = 1;
return row;
}

- (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];
    cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
    cell.textLabel.numberOfLines = 0;
    cell.textLabel.font = [UIFont fontWithName:@"Heiti TC" size:17.0];
}

// Configure the cell...
if (tableView == searchDisplayController.searchResultsTableView)
{
    cell.textLabel.text = [self.filteredListContent objectAtIndex:indexPath.row];
}
else
{
    cell.textLabel.text = [self.listContent objectAtIndex:indexPath.row];
}

return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedItem;

if (tableView == self.searchDisplayController.searchResultsTableView)
{
    selectedItem = [self.filteredListContent objectAtIndex:indexPath.row];
}
else
{
    selectedItem = [self.listContent objectAtIndex:indexPath.row];
}

// Is the selection a category?
//    NSArray *cats = [DBAdapter allCategories];
__block BOOL cat = NO;
[cats enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    if ([(NSString*)obj isEqualToString:selectedItem]) {
        cat = YES;
        *stop = YES;
    }
}];

if (cat) { // the user's selection was a category
//      NSLog(@"Selected item was a category");
}
else {
    NSArray *mans = [DBAdapter allManufacturers];
    __block BOOL man = NO;
    [mans enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        if ([(NSString*)obj isEqualToString:selectedItem]) {
            man = YES;
            *stop = YES;
        }
    }];
    if (man) { // the user's selection was a manufacturer
//        NSLog(@"Selected item was a manufacturer");
    } else {
        // the user's selection was a product

        // Find selectedItem in products
        __block NSDictionary *selectedRow = nil;
        [self.everything enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
{
            //everything is an array of dictionaries 
            if ([(NSString*)[(NSDictionary*)obj objectForKey:@"Title"] isEqualToString:selectedItem]) {
                selectedRow = (NSDictionary*)obj;
                *stop = YES;
            }
        }];

        MenuData *selectionData =  [MenuData menuData];
        selectionData.manufacturerID = [[selectedRow objectForKey:@"Manufacturer_id"] integerValue];
        selectionData.categoryID = [[selectedRow objectForKey:@"Category_id"] integerValue];
        selectionData.sCategoryID = [[selectedRow objectForKey:@"SubCategory_id"] integerValue];
        selectionData.ssCategoryID = [[selectedRow objectForKey:@"SuperSubCategory_id"] integerValue];

        NSString *selectedTitle = [selectedRow objectForKey: @"Title"];  // You probably already have this value from your search. Here for the sake of clarity.

        NSDictionary *productDetails = [DBAdapter productDetails: selectedTitle forCurrentData: selectionData];


        NSArray *allKeys = [productDetails allKeys];
//        NSLog(@"values: %i", [allKeys count]);
        for (NSString *key in allKeys) {
            id value = [productDetails objectForKey:key];
            if ([value isKindOfClass:[NSString class]]) {
          //      NSLog(@"key: %@  value: %@", key, value); 
            }
        }

        NSInteger ViewNumber = [[productDetails objectForKey:@"View"] integerValue];
        switch (ViewNumber) {
            case 25: {
                DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
                dvController.dictionary = productDetails;
                [self.navigationController pushViewController:dvController animated:YES];
            }
                break;
            case 18: {
                EffectDetailViewController *edvController = [[EffectDetailViewController alloc] initWithNibName:@"EffectDetailView" bundle:[NSBundle mainBundle]];
                edvController.dictionary = productDetails;
                [self.navigationController pushViewController:edvController animated:YES];
            }
                break;
            case 17: {
                ConsoleDetailController *cdvController = [[ConsoleDetailController alloc] initWithNibName:@"ConsoleDetailController" bundle:[NSBundle mainBundle]];
                cdvController.dictionary = productDetails;
                [self.navigationController pushViewController:cdvController animated:YES];
            }
                break;
            case 2: {
                ConsoleDetailController *cdvController = [[ConsoleDetailController alloc] initWithNibName:@"ConsoleDetailController" bundle:[NSBundle mainBundle]];
                cdvController.dictionary = productDetails;
                [self.navigationController pushViewController:cdvController animated:YES];
            }
                break;
            case 3: {
                DimmersDetailController *ddvController = [[DimmersDetailController alloc] initWithNibName:@"DimmersDetailController" bundle:[NSBundle mainBundle]];
                ddvController.dictionary = productDetails;
                [self.navigationController pushViewController:ddvController animated:YES];
            }
                break;
            case 12: {
                ConventionalController *cController = [[ConventionalController alloc] initWithNibName:@"ConventionalController" bundle:[NSBundle mainBundle]];
                cController.dictionary = productDetails;
                [self.navigationController pushViewController:cController animated:YES];
            }
                break;
            case 5: {
                ProDetailViewController *pController = [[ProDetailViewController alloc] initWithNibName:@"ProDetailViewController" bundle:[NSBundle mainBundle]];
                pController.dictionary = productDetails;
                [self.navigationController pushViewController:pController animated:YES];
            }
                break;

        }


    }
}

}

#pragma mark -
#pragma mark Content Filtering

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope {
/*
 Update the filtered array based on the search text and scope.
 */

[self.filteredListContent removeAllObjects]; // First clear the filtered array.

/*
 Search the main list for products whose type matches the scope (if selected) and whose name matches searchText; add items that match to the filtered array.
 */
for (NSString *product in listContent)
{
    //Edit AD - NS Range works instead of NSComparisonResult
    NSRange result = [product rangeOfString:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)];
    if (result.location != NSNotFound)
    {
        [self.filteredListContent addObject:product];
    }
    /*
     //  NSComparisonResult result = [product compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
     if (result == NSOrderedSame)
     {
     [self.filteredListContent addObject:product];
     }
     */
}
}

#pragma mark -
#pragma mark UISearchDisplayController Delegate Methods

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
[self filterContentForSearchText:searchString scope:
 [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];

// Return YES to cause the search result table view to be reloaded.
return YES;
}


- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption {
[self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope:
 [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];

// Return YES to cause the search result table view to be reloaded.
return YES;
}


- (void)refresh {
NSLog(@"Refresh");
if([NSThread isMainThread])
{
    [self.Table reloadData];
    [self.Table setNeedsLayout];
    [self.Table setNeedsDisplay];
}
else
{
    [self performSelectorOnMainThread:@selector(refresh) withObject:nil waitUntilDone:YES];
}
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:03:54+00:00Added an answer on June 10, 2026 at 10:03 pm

    You have 2 options.

    1. Remove the item from the listContent as well. This can be done via a delegate method that will be called from the child view controller when you delete the item.
    2. Move your viewDidLoad functionality where listContents is generated from the database to viewWillAppear. This will cause listContents to read the database again, after the item was deleted and you hit the back button, this will also get called when the view first opens.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a one-time need to create a file from an iOS mutable array.
I have a UITableView that was created from data coming from a mutable array.
I have a mutable array that has been retained. This array contain dictionaries with
I have an tableview which is loaded from a mutablearray as listed below. However
I have a mutable array of strings. For this example, let's say there are
I have a table populated with a mutable array. The cells are custom, with
I have a mutable array of managed objects that I get from Core Data
I have mutable string array named arrayout. It is having 3 element .Now I
I have an mutable array, allRows . In a loop, I assign each index
I have a mutable array that has about 100 objects in it and each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.