01-10-2010, 10:58 PM
#1 (permalink )
Registered Member
Join Date: Oct 2009
Posts: 9
If statement causes a 'SIGABRT' signal to be received
Hi Everyone,
In my program, I have a table. When the user selects a certain cell, I want it to take them to one of two different views, depending on which they pressed.
I am using an IF/ELSE statement to achieve this, however, I think there may be a problem with my code, because the program freezes up both on my Iphone, and in the simulator, and Xcode displays a message saying:
GDB: Program received signal: "SIGABRT"
So here is the IF statement, please have a look over it, and tell me what I am doing wrong, or give me some tips:
Code:
if (selectedItem = glossary) {
DisclosureViewController *dsController = [[DisclosureViewController alloc] initWithNibName:@"DisclosureView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dsController animated:YES];
[dsController release];
dsController = nil;
}
else {
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
dvController.selectedItem = selectedItem;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
}
Thanks in advance,
Aaron
01-10-2010, 11:07 PM
#2 (permalink )
Registered Member
Join Date: Oct 2009
Posts: 519
did you mean to do == instead of =?
01-10-2010, 11:13 PM
#3 (permalink )
Registered Member
Join Date: Oct 2009
Posts: 9
I added that in, and it still displays the SIGABRT error when I select the cell for the different view.
Thanks
Last edited by Sentis; 01-10-2010 at 11:27 PM .
01-10-2010, 11:34 PM
#4 (permalink )
Registered Member
Join Date: Oct 2009
Posts: 9
This might help.
These are the couple lines of code relating to the problem.
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedItem =[listOfItems objectAtIndex:indexPath.row];
NSString *glossary = @"Water";
thanks!
01-10-2010, 11:52 PM
#5 (permalink )
Registered Member
Join Date: Oct 2009
Posts: 519
where do you allocate listofitems array?
01-11-2010, 12:00 AM
#6 (permalink )
Registered Member
Join Date: Oct 2009
Posts: 9
In the ViewdidLoad method:
Code:
- (void)viewDidLoad {
[super viewDidLoad];
listOfItems = [[NSMutableArray alloc] init];
[listOfItems addObject:@"Periodic Table"];
01-11-2010, 12:18 AM
#7 (permalink )
Registered Member
Join Date: Nov 2009
Posts: 580
It's getting late, so I could be missing something, but I don't see any obvious issues with anything you've posted. You'll probably get better help if you post the entire class (or, if that's too big, at the very least the complete code to the didSelectRowAtIndexPath: method). It's very hard to debug when there's only a few brief excerpts of code scattered across multiple posts.
01-11-2010, 12:43 AM
#8 (permalink )
Registered Member
Join Date: Oct 2009
Posts: 9
Here is the full code:
Code:
#import "RootViewController.h"
#import "TableViewAppDelegate.h"
#import "DetailViewController.h"
#import "DisclosureViewController.h"
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
listOfItems = [[NSMutableArray alloc] init];
[listOfItems addObject:@"Periodic Table"];
[listOfItems addObject:@"Acids & Bases"];
[listOfItems addObject:@"Metals"];
[listOfItems addObject:@"Water"];
self.navigationItem.title = @"Blah";
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; }
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return[listOfItems count];
}
- (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] autorelease];
//cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
NSString *cellValue =[listOfItems objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedItem =[listOfItems objectAtIndex:indexPath.row];
NSString *glossary = @"Water";
if (selectedItem == glossary) {
DisclosureViewController *dsController = [[DisclosureViewController alloc] initWithNibName:@"DisclosureView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dsController animated:YES];
[dsController release];
dsController = nil;
}
else {
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
dvController.selectedItem = selectedItem;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
}
}
- (void)dealloc {
[listOfItems release];
[selectedItem release];
[glossary release];
[super dealloc];
}
@end
There are also a couple of warnings about local declarations of 'selectedItem' and 'glossary' hiding the instance variable ould that have anything to do with it?
thanks again!
Last edited by Sentis; 01-11-2010 at 12:49 AM .
01-11-2010, 01:22 AM
#9 (permalink )
Registered Member
Join Date: Oct 2009
Posts: 9
I found the problem.
The If statement is fine! the problem occurs sometime during the loading of the 'Disclosure View'. But i have it worked out.
Thanks again for all of your help!
01-11-2010, 01:26 AM
#10 (permalink )
Registered Member
Join Date: Oct 2009
Location: Mataró, Barcelona, Spain
Posts: 14
I think the problem is in
Code:
if (selectedItem == glossary)
You can't compare strings with ==
Try
Code:
if ([selectedItem isEqualToString: glossary])
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 271
20 members and 251 guests
ADY , AragornSG , Bertrand21 , Dani77 , Dattee , fkmtc , HDshot , HemiMG , iDifferent , JasonR , macquitzon216 , mer10 , prchn4christ , Rudy , sacha1996 , sneaky , spiderguy84 , Sunny46 , theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp