1
爲了努力練習MVC(也鬆散地遵循教程),我已經放置了一個方法,將地址簿聯繫人導入從NSObject
繼承的,名爲Model.h
的單獨數據類中。它不是UIViewController
而是NSObject
。IOS:訪問來自NSObject的故事板
我遇到的問題是,如果訪問聯繫人被拒絕,我想跳轉到另一個視圖控制器。而NSObject
顯然不會給你訪問storyboard
。
模型和處理所發生事件的視圖控制器之間的通信目前通過NSNotificationCenter
,但我無法弄清楚如何簡潔地傳達用戶拒絕訪問聯繫人的事實。
任何人都可以建議允許從NSObject
訪問故事板或從NSObject
與活動UIViewController
通信,該訪問已被拒絕。
- (void)fetchAddressBookContacts
{
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
switch (ABAddressBookGetAuthorizationStatus()) {
case kABAuthorizationStatusAuthorized:
{
NSLog(@"User has already granted access to the Address Book");
[self extractContactsFromAddressBookAlt];
break;
}
case kABAuthorizationStatusDenied:
{
NSLog(@"User has denied access to the Address Book");
dispatch_async(dispatch_get_main_queue(), ^{
[self gotoNewVC];//does not work
});
break;
}
}
if (addressBook) {
CFRelease(addressBook);}
}
//following is not getting called from NSObject
-(void) gotoNewVC {
UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"newVC"];
UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController];
self.window.rootViewController = navigation;
}