TTNavigator URL 值与当前 VC 不匹配

发布于 2024-11-24 10:36:58 字数 5713 浏览 1 评论 0原文

大家好,我想问一下你们中是否有人遇到过像我这样的问题。我一直在使用Three20框架的TTNavigator进行一个项目。每个视图都按其应有的方式显示和转换。我有一个应用程序菜单,其中包含应用程序各自模块的按钮。问题是,当我单击特定模块的按钮并显示该视图时,TTNavigator 的 URL 属性值是应用程序的菜单视图 (tt://mainMenu) 的 URL 属性值,而不是模块的初始视图 (例如“tt://messageBoard”或“tt://profilePage”)。我已经检查并审查了可能与此问题相关的必要代码块,但我似乎无法解决手头的错误。

这是我的 AppDelegate 的定义

#import "Three20TestAppDelegate.h"
#import "StartViewController.h"
#import "JumpsiteProfilePage.h"
#import "MenuViewController.h"
#import "BNDefaultStylesheet.h"
#import "MessageBoardViewController.h"
#import "GroupListViewController.h"
#import "DrillDownGroupListView.h"
#import "ProfileListViewController.h"
#import "ProfileDetailsViewController.h"

#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

@implementation UINavigationBar (UINavigationBarCategory)
-(void)drawRect:(CGRect)rect{

UIImage *image = [UIImage imageNamed:@"NavBar BG.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];

self.tintColor = UIColorFromRGB(0xFFD900);

}
@end

@implementation UIToolbar (UIToolbarCategory)
-(void)drawRect:(CGRect)rect{

UIImage *image = [UIImage imageNamed:@"NavBar BG.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];

self.tintColor = UIColorFromRGB(0xFFD900);
[super drawRect:rect];
}



@end


@implementation Three20TestAppDelegate


@synthesize window=_window;

@synthesize managedObjectContext=__managedObjectContext;

@synthesize managedObjectModel=__managedObjectModel;

@synthesize persistentStoreCoordinator=__persistentStoreCoordinator;

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

TTNavigator *navigator = [TTNavigator navigator];
navigator.window = _window;
navigator.persistenceMode = TTNavigatorPersistenceModeAll;
navigator.supportsShakeToReload = YES;

[TTStyleSheet setGlobalStyleSheet:[[[BNDefaultStylesheet alloc] init] autorelease]]; 

TTURLMap *map = navigator.URLMap;

//startView(Log-in View)
[map from:@"tt://startView"
 toSharedViewController:[StartViewController class]];

//Application's Menu
[map from:@"tt://mainMenu" 
toSharedViewController:[MenuViewController class]];

//User's Profile module
[map from:@"tt://profilePage" 
toSharedViewController:[JumpsiteProfilePage class]];

//Message Board module
[map from:@"tt://messageBoard" 
toSharedViewController:[MessageBoardViewController class]];
[map from:@"tt://groupList" 
toSharedViewController:[GroupListViewController class]];
[map from:@"tt://drillDownListView" 
toSharedViewController:[DrillDownGroupListView class]];

//Profile List module
[map from:@"tt://profileList" 
toViewController:[ProfileListViewController class]];
[map from:@"tt://profileDetailsList" 
toSharedViewController:[ProfileDetailsViewController class]];  

[navigator openURLAction:[TTURLAction actionWithURLPath:@"tt://startView"]];

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

- (void)applicationWillResignActive:(UIApplication *)application
{
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
}

- (void)applicationWillTerminate:(UIApplication *)application
{
[self saveContext];
}

- (void)dealloc
{
[_window release];
[__managedObjectContext release];
[__managedObjectModel release];
[__persistentStoreCoordinator release];
[super dealloc];
}

- (void)awakeFromNib
{
}

- (void)saveContext
{
NSError *error = nil;
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
if (managedObjectContext != nil)
{
    if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error])
    {
        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:@"Three20Test" withExtension:@"momd"];
__managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];    
return __managedObjectModel;
}

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (__persistentStoreCoordinator != nil)
{
    return __persistentStoreCoordinator;
}

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Three20Test.sqlite"];

NSError *error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil 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

Good day guys, I would like to inquire if anyone of you may have encountered a problem like mine. I have been working on a project using the TTNavigator of the Three20 framework. Every view is displayed and transitioned as it should be. I have an App menu that has buttons to the application's respective modules. The problem is that, when i click the button to a particular module, and when that view is displayed, the URL property value of the TTNavigator is that of the app's menu view (tt://mainMenu) and not the module's initial View (e.g. "tt://messageBoard" or "tt://profilePage"). i have checked and reviewed the necessary code blocks to which this problem may be linked to but i can't seem to fine the fault at hand.

Here's the definition for my AppDelegate

#import "Three20TestAppDelegate.h"
#import "StartViewController.h"
#import "JumpsiteProfilePage.h"
#import "MenuViewController.h"
#import "BNDefaultStylesheet.h"
#import "MessageBoardViewController.h"
#import "GroupListViewController.h"
#import "DrillDownGroupListView.h"
#import "ProfileListViewController.h"
#import "ProfileDetailsViewController.h"

#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

@implementation UINavigationBar (UINavigationBarCategory)
-(void)drawRect:(CGRect)rect{

UIImage *image = [UIImage imageNamed:@"NavBar BG.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];

self.tintColor = UIColorFromRGB(0xFFD900);

}
@end

@implementation UIToolbar (UIToolbarCategory)
-(void)drawRect:(CGRect)rect{

UIImage *image = [UIImage imageNamed:@"NavBar BG.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];

self.tintColor = UIColorFromRGB(0xFFD900);
[super drawRect:rect];
}



@end


@implementation Three20TestAppDelegate


@synthesize window=_window;

@synthesize managedObjectContext=__managedObjectContext;

@synthesize managedObjectModel=__managedObjectModel;

@synthesize persistentStoreCoordinator=__persistentStoreCoordinator;

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

TTNavigator *navigator = [TTNavigator navigator];
navigator.window = _window;
navigator.persistenceMode = TTNavigatorPersistenceModeAll;
navigator.supportsShakeToReload = YES;

[TTStyleSheet setGlobalStyleSheet:[[[BNDefaultStylesheet alloc] init] autorelease]]; 

TTURLMap *map = navigator.URLMap;

//startView(Log-in View)
[map from:@"tt://startView"
 toSharedViewController:[StartViewController class]];

//Application's Menu
[map from:@"tt://mainMenu" 
toSharedViewController:[MenuViewController class]];

//User's Profile module
[map from:@"tt://profilePage" 
toSharedViewController:[JumpsiteProfilePage class]];

//Message Board module
[map from:@"tt://messageBoard" 
toSharedViewController:[MessageBoardViewController class]];
[map from:@"tt://groupList" 
toSharedViewController:[GroupListViewController class]];
[map from:@"tt://drillDownListView" 
toSharedViewController:[DrillDownGroupListView class]];

//Profile List module
[map from:@"tt://profileList" 
toViewController:[ProfileListViewController class]];
[map from:@"tt://profileDetailsList" 
toSharedViewController:[ProfileDetailsViewController class]];  

[navigator openURLAction:[TTURLAction actionWithURLPath:@"tt://startView"]];

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

- (void)applicationWillResignActive:(UIApplication *)application
{
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
}

- (void)applicationWillTerminate:(UIApplication *)application
{
[self saveContext];
}

- (void)dealloc
{
[_window release];
[__managedObjectContext release];
[__managedObjectModel release];
[__persistentStoreCoordinator release];
[super dealloc];
}

- (void)awakeFromNib
{
}

- (void)saveContext
{
NSError *error = nil;
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
if (managedObjectContext != nil)
{
    if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error])
    {
        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:@"Three20Test" withExtension:@"momd"];
__managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];    
return __managedObjectModel;
}

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (__persistentStoreCoordinator != nil)
{
    return __persistentStoreCoordinator;
}

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Three20Test.sqlite"];

NSError *error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不会写诗 2024-12-01 10:36:58

将 ViewController 调用映射

[map from:kAppRootURLPath toViewController:[HomeThumbnailViewController class]];

到 ViewController

TTURLAction *urlAction=[[[TTURLAction alloc] initWithURLPath:strTTURL] autorelease];
urlAction.animated=YES;
[[TTNavigator navigator]openURLAction:urlAction];

Mapping ViewController

[map from:kAppRootURLPath toViewController:[HomeThumbnailViewController class]];

Call to ViewController

TTURLAction *urlAction=[[[TTURLAction alloc] initWithURLPath:strTTURL] autorelease];
urlAction.animated=YES;
[[TTNavigator navigator]openURLAction:urlAction];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文