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 8311943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:59:03+00:00 2026-06-08T19:59:03+00:00

This is the code for my SearchViewController. But when I push to the nextController,

  • 0

This is the code for my SearchViewController. But when I push to the nextController, the app crashes and it doesn’t reach nextController, or in some cases I get a glance at it before crash. I recieve an error “bad instance sent to selector” in log. The SearchViewController has a NavigationController attatched in storyboard, and I push through the navigation controller as you see.

If I change ‘pushViewController’ to ‘presentModalViewController’ , it’s now able to load the UITableViewController, but it now crashes if I scroll(swipe) the TableView if it’s populated with results. If it’s empty (no matching results) it’s not crashing. Weird. Also, no navigation bar above TableView.

Can you tell me what I’m doing wrong and help me correct it? Got a feeling it’s an easy issue.

SearchViewController.h

#import <UIKit/UIKit.h>

@interface SearchViewController : UIViewController

@property (nonatomic, strong) NSMutableArray *allObjectsArray;
@property (nonatomic, strong) NSMutableArray *resultObjectsArray;

@property (nonatomic, strong) IBOutlet UITextField *nameTextField;


-(IBAction)searchButtonPressed:(id)sender;

@end

SearchViewController.m

-(IBAction)searchButtonPressed:(id)sender{  


    NSString *path = [[NSBundle mainBundle] pathForResource:@"Wine" ofType:@"plist"];
    allObjectsArray = [[NSMutableArray alloc] initWithContentsOfFile:path];

    NSString *nameString = [NSString stringWithFormat:@"%@", [nameTextField text]];

    resultObjectsArray = [NSMutableArray array];
    for(NSDictionary *wine in allObjectsArray)
    {
        NSString *wineName = [wine objectForKey:@"Name"];
        NSRange range = [wineName rangeOfString:nameString options:NSCaseInsensitiveSearch];
        if(range.location != NSNotFound)
        [resultObjectsArray addObject:wine];
    }

NSLog(@"Objects: %@", allObjectsArray);

ResultsTableViewController *nextController = [[self storyboard] instantiateViewControllerWithIdentifier:@"ResultsController"];

nextController.objectsArray = [[NSMutableArray alloc]initWithArray:resultObjectsArray];

NSLog(@"Results: %@", nextController.objectsArray);
[self.navigationController pushViewController:nextController animated:YES];
[nextController release];
}

and this is objectsArray in nextController which populates the UITableView:

@property (nonatomic, strong) NSMutableArray *objectsArray;

ResultsTableViewController.m:

#import "ResultsTableViewController.h"

@interface ResultsTableViewController ()

@end

@implementation ResultsTableViewController

@synthesize objectsArray;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
 NSLog(@"%s", __FUNCTION__);

// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [objectsArray count];
NSLog(@"%s", __FUNCTION__);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%s", __FUNCTION__);
static NSString *CellIdentifier = @"searchResultCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    // Use the default cell style.
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"searchResultCell"] autorelease];
}


// Configure the cell...
cell.textLabel.text = [[objectsArray objectAtIndex:indexPath.row] valueForKey:@"Name"];

return cell;
}

@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-08T19:59:05+00:00Added an answer on June 8, 2026 at 7:59 pm

    (posting as an answer – see details in comments of the question)

    Are you using or are you not using ARC? Because, you have some [UIViewController release] there…

    (as for the self.objectsArray)

    cell.textLabel.text = [[self.objectsArray objectAtIndex:indexPath.row] valueForKey:@"Name"];
    
    • and on the other occasions. then, you’ll assure to use property getter… the same with setting the value; self.objectsArray = ...; but only, when you are accessing the property; provided, you have it properly @synthesize-d

    (and one more thing, just a nit-picking)

    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    
    • use constants as identifiers as much as possible, definitelly when you already have it defined in scope

    Btw, I’ve just noticed, you wrote “you’ve just deactivated the ARC for some other code to work”… you don’t have to, you can disable ARC on per file basis; and if you don’t have memory management and obj-c experience, just don’t disable ARC when you have it. It’s a nice addition to iPhone Obj-C… refer to my post on how to per-class disable ARC: Adding UIActivityIndicator to UITableView

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code works some of the time, but then sometimes crashes with a EXC_BAD_ACCESS
This code works fine for FF, Safari, Chrome and IE9, but doesn't work 100%
This code works fine in <= IE7, but it doesn't work in firefox ..
This code fails on some machines: // Parse error: syntax error, unexpected '[' ...
This code : http://jsfiddle.net/bYtTG/1/ Works as I want in FF, chrome and opera, but
This code is not pretty, but I want to print out the last generated
I've had this sort of problem before, and it didn't get a satisfactory answer.
This code is ment to download the source code of an html file but
This code is reading from mysql db tables and should return few names. But
This code runs perfectly on Java but when I run this on Android platform,

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.