views:

471

answers:

2

Hello everyone. My app is consisted of 2 views. The MainView and ResultsView. MainView contains a UITextField that needs to be filled and then if a button is touched, the view changes to ResultsView. Below is the juicy part of the code that handles that.

// In CallerIDAppDelegate.h
@class MainViewController;
@class ResultsViewController;

@interface CallerIDAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;

IBOutlet MainViewController *mainViewController; IBOutlet ResultsViewController *resultsViewController;

NSString *phoneNumber;

NSMutableArray *parsingResults;

BOOL isSearchingForSaved; } [...]

// In CallerIDAppDelegate.m
[...]
- (void)applicationDidFinishLaunching:(UIApplication *)application {

/* Set up and display MainView */ MainViewController *mainController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:[NSBundle mainBundle]]; self.mainViewController = mainController; [window addSubview:mainController.view];

// Override point for customization after application launch [window makeKeyAndVisible]; }

-(void)switchViews{

if(self.resultsViewController == nil){ ResultsViewController *resultsController = [[ResultsViewController alloc] initWithNibName:@"ResultsViewController" bundle:nil]; self.resultsViewController = resultsController; [resultsController release]; }

if(self.mainViewController.view.superview == nil){

[resultsViewController.view removeFromSuperview]; [window insertSubview:mainViewController.view atIndex:0];

} else {

[mainViewController.view removeFromSuperview]; [window insertSubview:resultsViewController.view atIndex:0];

}

  }
  [...]

Now in ResultsView I have a tableview with some content. What I want to do is when a row from that tableview is selected I want to invoke the ABUnknownPersonViewController so the user can save a contact to the addressbook

So in ResultsViewController.m

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   [...]
 ABUnknownPersonViewController *unknownPersonView = [[[ABUnknownPersonViewController alloc] init] autorelease];

[unknownPersonView setUnknownPersonViewDelegate:self];

[unknownPersonView setDisplayedPerson:personRecord]; [unknownPersonView setAllowsAddingToAddressBook:YES];

UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:unknownPersonView] autorelease];

[self presentModalViewController:navigationController animated:YES];

}

- (void)unknownPersonViewController:(ABUnknownPersonViewController *)unknownPersonView didResolveToPerson:(ABRecordRef)person {

CallerIDAppDelegate *delegate = (CallerIDAppDelegate *)[[UIApplication sharedApplication] delegate]; DLog("Called!"); [self dismissModalViewControllerAnimated:YES]; //caused crash

    // Caused crash too
    //[delegate.resultsViewController dismissModalViewControllerAnimate:YES]; 
    }

The ABUnknownPersonViewController is displayed properly when the row is selected. It also contains all the correct info that was sent through personRecord and saves the contact properly in addressbook when Add to Contacts button is pressed. BUT.. when the done (or cancel) button is pressed in the last step it crashes pretty BAD!

The problem is i cant understand anything from debugger since when launched it says Loading 43453 stack frames.. which procedure I stop. The top of the stack trace is:

[CALayer sublayers];

and then there are a LOT of

[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:]

Please enlighten me.. i am sure its probably a little stupid thing that I do wrong. I've been trying for hours to fix that but I cant :(

Thanx in advance

+2  A: 

Fix it..... it was indeed stupid.

It should be:

- (void)unknownPersonViewController:(ABUnknownPersonViewController *)unknownPersonView didResolveToPerson:(ABRecordRef)person {
CallerIDAppDelegate *delegate = (CallerIDAppDelegate *)[[UIApplication sharedApplication] delegate];
DLog("Called!");
[unknownPersonView dismissModalViewControllerAnimated:YES];

}

epron
The solutions you learn the most from are the ones you find yourself. Welcome to Stack Overflow :)
h4xxr
A: 

I have a similar kind of problem, The problem goes this way - when I select "Add to existing" option, people picker controller is shown automatically by ABUnknownPersonViewController. - Now I want to dismiss this people picker programmaticaly, If I just do dismissModalViewController, it does not remove the people picker. Please suggest how that can be achived. Thanx in advance

Ashishail