问题
I'm very newbie with Three20. I'm trying to make an TTLauncherView based interface, without success for now.
My LauncherView contains a button, mapped to an URL. When I click on this button, I want a TTTableView based to be displayed on screen. But I have nothing.
Here is a piece of my AppDelegate code :
[map from:@"tt://rank" toViewController:[RankController class]];
And the LauncherView code (a piece, too) :
launcherView.pages = [NSArray arrayWithObjects:
[NSArray arrayWithObjects:
[[[TTLauncherItem alloc]
initWithTitle:@"Rank"
image:@"bundle://defaultMusic.png"
URL:@"tt://rank"
canDelete:YES] autorelease],nil], nil];
The button is here, no problem. But when clicked, it never opens my RankController class. Here is its source :
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
self.title = @"Rank";
self.variableHeightRows = YES;
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void) createModel
{
NSLog(@"rank");
self.dataSource = [TTSectionedDataSource dataSourceWithObjects:
@"Items",
[TTTableTextItem itemWithText:@"Item n°1" URL:nil],
[TTTableTextItem itemWithText:@"Item n°2" URL:nil],
[TTTableTextItem itemWithText:@"Item n°3" URL:nil],
[TTTableTextItem itemWithText:@"Item n°4" URL:nil],
[TTTableTextItem itemWithText:@"Item n°5" URL:nil],
nil];
}
I tried to proceed the same way that the examples packaged in Three20, so what am I doing wrong ?
Thanks in advance
回答1:
You need to implement the TTLauncherViewDelegate. In your .h file, declare your view controller to implement the TTLauncherViewDelegate:
@interface SFLauncherViewController : TTViewController <TTLauncherViewDelegate>
Then in .m file, implement this method:
- (void)launcherView:(TTLauncherView *)launcher didSelectItem:(TTLauncherItem *)item{
NSLog(@"did select item: %@", [item URL]);
TTNavigator *navigator = [TTNavigator navigator];
TTURLAction *action = [[TTURLAction actionWithURLPath:[item URL]] applyAnimated:YES];
[navigator openURLAction:action];
}
来源:https://stackoverflow.com/questions/3934075/how-to-launch-a-tttableview-based-view-with-ttlauncherview