我的应用由 2 个视图组成。主视图和结果视图。MainView 包含需要填充的 UITextField,然后如果触摸按钮,视图将更改为 ResultsView。下面是处理该问题的代码的有趣部分。
// 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];
}
}
现在ResultsView
我有一个包含一些内容的表格视图。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.
所以在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];
}
选择ABUnknownPersonViewController
行时正确显示。它还包含所有发送的正确信息,personRecord
并在按下“添加到联系人”按钮时将联系人正确保存在地址簿中。但是,当在最后一步按下完成(或取消)按钮时,它会崩溃非常糟糕!
问题是,我无法理解调试器中的任何内容,因为在启动时,它会显示“正在加载 43453 个堆栈帧……”,我停止了该过程。堆栈跟踪的顶部是:
[CALayer sublayers];
然后有很多
[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:]
请赐教。我敢肯定,我做错了可能有点愚蠢。我已经尝试了几个小时来解决这个问题,但我做不到。:(