- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 Storyboard 和 XCode 4.3 创建一个将选项卡栏作为 Root View 的应用程序。尽管我的应用程序有其他运行良好的转场,但其中一个转场不会触发。它应该在选择选项卡的第三项时触发。我唯一能看到的是标签栏实际上加载了新 View ,但没有传递任何信息。
Storyboard 上的连接如下:Root View controller (Tab bar) -> Navigation Controller -> CapitolDetailViewController(它有来自另一个 View Controller 的 push segue)
我已经在连接、代码等方面尝试了很多更改。但是它并没有触发这个 segue。我试图更改我的 AppDelegate 中的代码以添加缺少的新 Controller 。我的 applicationDidFinishLaunching 的代码如下:
NSManagedObjectContext *context = [self managedObjectContext];
NSError *error;
if (![context save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}
tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *view1 = [[tabBarController viewControllers] objectAtIndex:0];
UINavigationController *view2 = [[tabBarController viewControllers] objectAtIndex:1];
UINavigationController *view3 = [[tabBarController viewControllers] objectAtIndex:2];
SCDMasterViewController *view11 = [[view1 viewControllers] objectAtIndex:0];
view11.managedObjectContext = self.managedObjectContext;
SerieDetailViewController *view22 = [[view2 viewControllers] objectAtIndex:0];
CapitolDetailViewController *view33 = [[view3 viewControllers] objectAtIndex:0];
return YES;
其中“SerieDetailViewController”是应该在选择第 3 项时传递信息的那个,而“CapitolDetailViewController”是应该接收它的那个。
我的 segue 代码:(它甚至没有进入 segue,de NSLOG 从未出现)
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSLog(@"Entra segue");
if ([segue.identifier isEqualToString:@"mostraCapitol"]) {
NSString *nom = @"";
nom= serieName;
CapitolDetailViewController *destViewController = segue.destinationViewController;
destViewController.serieName2 = nom;
}
}
有谁知道是怎么回事吗?
更新:尽管我收到了帮助我更正一些编译错误的答案,但问题仍然存在。如果我单击选项卡栏项目,它会加载一个空 View 。它从不调用 segue。看起来标签栏项目和 View Controller 没有附加。
最佳答案
尝试检查不起作用的 segue 方法。确保 Storyboard中 segue 的标识符与类(class)中的标识符一致。从您的代码和所有注释的外观来看,您的代码似乎很好并且应该可以工作。唯一可能给您带来问题的地方是 Storyboard中 segue 的不同标识符。我希望这能解决您的问题,我的 friend 。
编辑:
好吧,我不知道这是否适合你,但我有不同的方法来设置标签栏应用程序中的核心数据。在委托(delegate)的 .h 文件中,几乎所有内容都是通用的,在 .m 中,特别是 applicationdidfinishwithoption
我使用索引号对添加到选项卡栏的 View Controller 中的 View 进行排序。我希望这会有所帮助,这是我使用的代码。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self setupFetchedResultsController];
if (![[self.fetchedResultsController fetchedObjects] count] > 0 ) {
NSLog(@"!!!!! ~~> There's nothing in the database so defaults will be inserted");
[self importCoreDataDefaultRoles];
}
else {
NSLog(@"There's stuff in the database so skipping the import of default data");
}
// The Tab Bar
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
// The Two Navigation Controllers attached to the Tab Bar (At Tab Bar Indexes 0 and 1)
UINavigationController *view1 = [[tabBarController viewControllers] objectAtIndex:0];
UINavigationController *view2 = [[tabBarController viewControllers] objectAtIndex:1];
View1 *view1 = [[view1nav viewControllers] objectAtIndex:0];
personsTVC.managedObjectContext = self.managedObjectContext;
View2 *view2 = [[view2nav viewControllers] objectAtIndex:0];
rolesTVC.managedObjectContext = self.managedObjectContext;
return YES;
}
通过使用索引号,我能够在没有任何错误的情况下实现相同的场景,并且对于启动 View ,我使用了一个我插入的 subview 作为初始模态视图。希望这对你有帮助。在我的例子中,核心数据被添加到多个选项卡,我不知道你是否有同样的需求。
编辑 1
这是我的Appdelegate.h
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
@end
这是app delegate.m
#import "AppDelegate.h"
#import "PersonsTVC.h"
#import "RolesTVC.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize managedObjectContext = __managedObjectContext;
@synthesize managedObjectModel = __managedObjectModel;
@synthesize persistentStoreCoordinator = __persistentStoreCoordinator;
@synthesize fetchedResultsController = __fetchedResultsController;
- (void)insertRoleWithRoleName:(NSString *)roleName
{
Role *role = [NSEntityDescription insertNewObjectForEntityForName:@"Role"
inManagedObjectContext:self.managedObjectContext];
role.name = roleName;
[self.managedObjectContext save:nil];
}
- (void)importCoreDataDefaultRoles {
NSLog(@"Importing Core Data Default Values for Roles...");
[self insertRoleWithRoleName:@"Player 1"];
[self insertRoleWithRoleName:@"Player 2"];
[self insertRoleWithRoleName:@"Player 3"];
[self insertRoleWithRoleName:@"Player 4"];
[self insertRoleWithRoleName:@"Player 5"];
[self insertRoleWithRoleName:@"Player 6"];
[self insertRoleWithRoleName:@"Player 7"];
[self insertRoleWithRoleName:@"Player 8"];
[self insertRoleWithRoleName:@"Player 9"];
[self insertRoleWithRoleName:@"Player 10"];
[self insertRoleWithRoleName:@"Player 11"];
[self insertRoleWithRoleName:@"Player 12"];
NSLog(@"Importing Core Data Default Values for Roles Completed!");
}
- (void)setupFetchedResultsController
{
// 1 - Decide what Entity you want
NSString *entityName = @"Role"; // Put your entity name here
NSLog(@"Setting up a Fetched Results Controller for the Entity named %@", entityName);
// 2 - Request that Entity
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];
// 3 - Filter it if you want
//request.predicate = [NSPredicate predicateWithFormat:@"Person.name = Blah"];
// 4 - Sort it if you want
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)]];
// 5 - Fetch it
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
[self.fetchedResultsController performFetch:nil];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self setupFetchedResultsController];
if (![[self.fetchedResultsController fetchedObjects] count] > 0 ) {
NSLog(@"!!!!! ~~> There's nothing in the database so defaults will be inserted");
[self importCoreDataDefaultRoles];
}
else {
NSLog(@"There's stuff in the database so skipping the import of default data");
}
// The Tab Bar
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
// The Two Navigation Controllers attached to the Tab Bar (At Tab Bar Indexes 0 and 1)
UINavigationController *personsTVCnav = [[tabBarController viewControllers] objectAtIndex:0];
UINavigationController *rolesTVCnav = [[tabBarController viewControllers] objectAtIndex:1];
// The Persons Table View Controller (First Nav Controller Index 0)
PersonsTVC *personsTVC = [[personsTVCnav viewControllers] objectAtIndex:0];
personsTVC.managedObjectContext = self.managedObjectContext;
// The Roles Table View Controller (Second Nav Controller Index 0)
RolesTVC *rolesTVC = [[rolesTVCnav viewControllers] objectAtIndex:0];
rolesTVC.managedObjectContext = self.managedObjectContext;
//NOTE: Be very careful to change these indexes if you change the tab order
// Override point for customization after application launch.
// UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
// RolesTVC *controller = (RolesTVC *)navigationController.topViewController;
// controller.managedObjectContext = self.managedObjectContext;
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
}
- (void)applicationWillTerminate:(UIApplication *)application
{
[self saveContext];
}
- (void)saveContext
{
NSError *error = nil;
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
if (managedObjectContext != nil)
{
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error])
{
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
}
#pragma mark - Core Data stack
- (NSManagedObjectContext *)managedObjectContext
{
if (__managedObjectContext != nil)
{
return __managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil)
{
__managedObjectContext = [[NSManagedObjectContext alloc] init];
[__managedObjectContext setPersistentStoreCoordinator:coordinator];
}
return __managedObjectContext;
}
- (NSManagedObjectModel *)managedObjectModel
{
if (__managedObjectModel != nil)
{
return __managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Model" withExtension:@"momd"];
__managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return __managedObjectModel;
}
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (__persistentStoreCoordinator != nil)
{
return __persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"StaffManager.sqlite"];
NSError *error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return __persistentStoreCoordinator;
}
#pragma mark - Application's Documents directory
- (NSURL *)applicationDocumentsDirectory
{
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}
@end
现在请记住,我将这两个类都用于数据实体,并在两个类中声明了托管对象。在使用核心数据时,可以肯定的是,您的初始 View 必须具有托管对象。如果这对您没有帮助,那么我建议您可以看看蒂姆·罗德利的核心数据教程或保罗·哈格蒂的斯坦福核心数据类(class)。如果您需要查看整个项目,请告诉我,我会尝试将一些东西放在一起并放置一个链接以便您可以下载它,但我相信如果您已经创建了一个合适的模型并且在应用程序委托(delegate)中使用了类似于以下内容的正确方法我所做的,它应该工作。希望这对你有帮助,我的 friend 。
关于ios - Segue 不会在标签栏应用程序中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14742514/
尝试使用集成到 QTCreator 的表单编辑器,但即使我将插件放入 QtCreator.app/Contents/MacOS/designer 也不会显示。不过,相同的 dylib 文件确实适用于独
在此代码示例中。 “this.method2();”之后会读到什么?在返回returnedValue之前会跳转到method2()吗? public int method1(int returnedV
我的项目有通过gradle配置的依赖项。我想添加以下依赖项: compile group: 'org.restlet.jse', name: 'org.restlet.ext.apispark', v
我将把我们基于 Windows 的客户管理软件移植到基于 Web 的软件。我发现 polymer 可能是一种选择。 但是,对于我们的使用,我们找不到 polymer 组件具有表格 View 、下拉菜单
我的项目文件夹 Project 中有一个文件夹,比如 ED 文件夹,当我在 Eclipse 中指定在哪里查找我写入的文件时 File file = new File("ED/text.txt"); e
这是奇怪的事情,这个有效: $('#box').css({"backgroundPosition": "0px 250px"}); 但这不起作用,它只是不改变位置: $('#box').animate
这个问题在这里已经有了答案: Why does OR 0 round numbers in Javascript? (3 个答案) 关闭 5 年前。 Mozilla JavaScript Guide
这个问题在这里已经有了答案: Is the function strcmpi in the C standard libary of ISO? (3 个答案) 关闭 8 年前。 我有一个问题,为什么
我目前使用的是共享主机方案,我不确定它使用的是哪个版本的 MySQL,但它似乎不支持 DATETIMEOFFSET 类型。 是否存在支持 DATETIMEOFFSET 的 MySQL 版本?或者有计划
研究 Seam 3,我发现 Seam Solder 允许将 @Named 注释应用于包 - 在这种情况下,该包中的所有 bean 都将自动命名,就好像它们符合条件一样@Named 他们自己。我没有看到
我知道 .append 偶尔会增加数组的容量并形成数组的新副本,但 .removeLast 会逆转这种情况并减少容量通过复制到一个新的更小的数组来改变数组? 最佳答案 否(或者至少如果是,则它是一个错
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
noexcept 函数说明符是否旨在 boost 性能,因为生成的对象中可能没有记录异常的代码,因此应尽可能将其添加到函数声明和定义中?我首先想到了可调用对象的包装器,其中 noexcept 可能会产
我正在使用 Angularjs 1.3.7,刚刚发现 Promise.all 在成功响应后不会更新 angularjs View ,而 $q.all 会。由于 Promises 包含在 native
我最近发现了这段JavaScript代码: Math.random() * 0x1000000 10.12345 10.12345 >> 0 10 > 10.12345 >>> 0 10 我使用
我正在编写一个玩具(物理)矢量库,并且遇到了 GHC 坚持认为函数应该具有 Integer 的问题。是他们的类型。我希望向量乘以向量以及标量(仅使用 * ),虽然这可以通过仅使用 Vector 来实现
PHP 的 mail() 函数发送邮件正常,但 Swiftmailer 的 Swift_MailTransport 不起作用! 这有效: mail('user@example.com', 'test
我尝试通过 php 脚本转储我的数据,但没有命令行。所以我用 this script 创建了我的 .sql 文件然后我尝试使用我的脚本: $link = mysql_connect($host, $u
使用 python 2.6.4 中的 sqlite3 标准库,以下查询在 sqlite3 命令行上运行良好: select segmentid, node_t, start, number,title
我最近发现了这段JavaScript代码: Math.random() * 0x1000000 10.12345 10.12345 >> 0 10 > 10.12345 >>> 0 10 我使用
我是一名优秀的程序员,十分优秀!