Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

NafisaBaker

macrumors newbie
Original poster
Dec 8, 2010
6
0
Hi everyone,

I've been trying to figure this issue out for a REALLY long time and any bit of help would be amazing, especially since I'm new to Objective-C.

Currently I'm making an app that has a tabBarController with one of the pages with a tableView which navigates to an info page of the object in that row.

Right now, what it does is initialize the table, but when I click on the row that I want, it crashes when I try to get to the next page. According to the debugger, its finding the name of the viewController, but not cannot load the next page.

Here's some code:

This is just the initialization of the tableview.
Code:
- (void)viewDidLoad {

	if (!pages)
	{
		pages = [[NSArray alloc] initWithObjects:@"CSLP", @"NSLS", @"LSPA", @"SIOP", @"Transfer", nil];
    }
	//menuLIst == sitesArray
    for (NSString *pageName in pages)
	{
		[self.menuList addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:
								  NSLocalizedString([pageName stringByAppendingString:@"Title"], @""), kTitleKey,
								  NSLocalizedString([pageName stringByAppendingString:@"Explain"], @""), kDetailKey,
								  nil]];
	}
	
	NSArray *sites = [[NSArray alloc] initWithObjects:@"CSLP", @"NSLS", @"LSPA", @"SIOP", @"Transfer Vision Program ", nil];
	self.sitesArray = sites; 
	
	
	UIImage *cslp = [UIImage imageNamed:@"CSLP LOGO.png"]; 
	UIImage *nsls = [UIImage imageNamed:@"NSLS LOGO.png"]; 
	UIImage *lspa = [UIImage imageNamed:@"LSPA LOGO.png"]; 
	UIImage *siop = [UIImage imageNamed:@"SIOP LOGO.png"]; 
	UIImage *transfer = [UIImage imageNamed:@"TRANSFER LOGO.png"];	
	NSArray *images = [[NSArray alloc] initWithObjects: cslp, nsls, lspa, siop, transfer, nil]; 
	[sites release]; 
	self.imagesArray = images; 
	

}

Code:
-(void) tableView:(UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath
{
	
	//NSInteger row = [indexPath row]; 
	
	
	NSMutableDictionary *rowData = [self.menuList objectAtIndex:indexPath.row];
	UIViewController *targetViewController = [rowData objectForKey:kViewControllerKey];
	if (!targetViewController)
	{
        // The view controller has not been created yet, create it and set it to our menuList array
        NSLog(@"pages objectAtIndex: %@", [[pages objectAtIndex:indexPath.row] stringByAppendingString:@"ViewController"]); 
		NSString *viewControllerName = [[pages objectAtIndex:indexPath.row] stringByAppendingString:@"ViewController"];
        NSLog(@"ViewControllerName: %@", viewControllerName); 
		targetViewController = [[NSClassFromString(viewControllerName) alloc] initWithNibName:viewControllerName bundle:nil];
        NSLog(@"targetViewController: %@", targetViewController); 

		
		SSARC_App_2AppDelegate *delegate = (SSARC_App_2AppDelegate*)[[UIApplication sharedApplication] delegate]; 
		[[delegate orgsNavigationController] pushViewController:targetViewController animated:YES];
	
		[delegate release]; 
		[rowData setValue:targetViewController forKey:kViewControllerKey];
	
	}
   
	[targetViewController release];

	
	
		
	 
	}

This is the initWithNibName for one of the viewControllers (which is the same for the rest)

Code:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
	if (!(self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
        return nil;
	self.title = NSLocalizedString(@"CSLPTitle", @"");
	
	return self;
	
}

Let me know if you need more code to understand the issue further.

Thanks!
 
The thing is there are no specifics. The console is clear, sans the NSLog statements I put in. It simply attempts to go to the next page and then crashes.
 
The thing is there are no specifics. The console is clear, sans the NSLog statements I put in. It simply attempts to go to the next page and then crashes.
Hmm, then how can you say this?:
According to the debugger, its finding the name of the viewController, but not cannot load the next page.
Anyways, can you look at the crash log and tell us what it's saying?
 
If you've done build & run targeted at the simulator, it should definitely post an error message to the console.

Alternatively, you should know roughly where the error could be based on your print statements. Have you tried setting some breakpoints both where in your TableViewController row selection method, as well as the initialization methods of your next view, to see what line the crash occurs on?
 
Well, when I step into the breakpoint at the didSelectRowAtIndex, the targetViewController is initialized as the viewController I want.

Are you asking for the debugger console output? Because so far all I have for that is this:
Code:
Pending breakpoint 1 - ""organizations.m":84" resolved
Pending breakpoint 2 - ""organizations.m":145" resolved
(gdb) continue
Current language:  auto; currently objective-c
2010-12-08 13:36:22.216 SSARC App 2[88153:207] pages objectAtIndex: CSLPViewController
2010-12-08 13:36:22.244 SSARC App 2[88153:207] ViewControllerName: CSLPViewController
2010-12-08 13:36:22.244 SSARC App 2[88153:207] targetViewController: <CSLPViewController: 0x5953490>
(gdb) continue
2010-12-08 13:37:08.656 SSARC App 2[88153:207] pages objectAtIndex: SIOPViewController
2010-12-08 13:37:08.657 SSARC App 2[88153:207] ViewControllerName: SIOPViewController
2010-12-08 13:37:08.658 SSARC App 2[88153:207] targetViewController: <SIOPViewController: 0x5c41f80>
(gdb)

However, upon further examination, after it leaves the didSelectRowAtIndex it seems to get stuck in an infinite loop as it keeps running and not going anywhere, allowing me to click on another table object, at which point it just stops running.
 
Try using "Step Over" instead of "Step Into".

However, upon further examination, after it leaves the didSelectRowAtIndex it seems to get stuck in an infinite loop as it keeps running and not going anywhere, allowing me to click on another table object, at which point it just stops running.

What segment of code is "after" the didSelectRowAtIndex method execution? The crash has to be somewhere, does it occur in this next segment? If you're using "Step Over" it should be pretty simple to pin point a line where it's occuring.
 
Last edited:
It gets to the end of the method didSelectRowAtIndexPath and then takes me to a place in the debugger with assembly calls. I don't know if this makes sense or not.
 
Uh, if I'm reading you correctly, you're using a Table View inside a tab view, but then you're trying to push on a new view controller by making a call to some "orgNavigationController" that you've grabbed from the app delegate.

This is beside the point but you're really misusing app delegate there, and really that's wrong.

Secondly, are you even instantiating a navigation controller somewhere? You don't get the ability to push on a new viewcontroller just because you're using a table view. Basically you need to read more about how this all works methinks.
 
@Dejo: Yes. I tried removing that just now as well and it produced the same results.

@Mathew: I went online and found a tutorial that explained that in order to do this I needed to create a navigation controller within the app delegate, which is its own class. Yes, I do instantiate the OrgsNavController in my app delegate and I have an instance of it in my tableView class. Are there any tutorials/readings that you suggest to get more information on this subject?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.