TTLauncherItem: change badge immediately (or: how to refresh TTLauncherView)

Posted by vikingosegundo on Stack Overflow See other posts from Stack Overflow or by vikingosegundo
Published on 2010-06-08T16:05:26Z Indexed on 2010/06/08 18:22 UTC
Read the original article Hit count: 637

Filed under:
|

I have a TTLauncherView with some TTLauncherItems. These show badges, representing messages from the network. I set the badges in viewWillAppear:, so if I switch to another view and then return, the correct badges are shown. But I want to update the badges as soon a message comes in.

Calling setNeedsDisplay on TTLauncherView doesn't help?

How can I refresh the TTLauncherView?

in my MessageReceiver class I do this:

TTNavigator* navigator = [TTNavigator navigator];

            [(OverviewController *)[navigator viewControllerForURL:@"tt://launcher"] reloadLauncherView] ;

My TTViewController-derived OverviewController

@implementation OverviewController


- (id)init {
  if (self = [super init]) {
    self.title = OverviewTitle;
  }
  return self;
}

- (void)dealloc {
    [items release];
    [overView release];
    [super dealloc];
}


-(void)viewDidLoad
{
    [super viewDidLoad];

    overView = [[TTLauncherView alloc] initWithFrame:self.view.bounds];
    overView.backgroundColor = [UIColor whiteColor];
    overView.delegate = self;
    overView.columnCount = 4;

    items = [[NSMutableArray alloc] init];
    for(int i = 1; i <= NumberOfBars; ++i){
        NSString *barID = [NSString stringWithFormat:NameFormat, IDPrefix, i];
        TTLauncherItem *item = [[[TTLauncherItem alloc] initWithTitle:barID
                                                                image:LogoPath
                                                                  URL:[NSString stringWithFormat:@"tt://item/%d", i]
                                                            canDelete:NO] autorelease];
        [barItems addObject: item];


    }
    overView.pages = [NSArray arrayWithObject:items];
    [self.view addSubview:overView];

}

-(void)viewWillAppear:(BOOL)animated
{


    for(int i = 0; i <[barItems count]; i++){
        TTLauncherItem *item = [items objectAtIndex:i];
        NSString *barID = [NSString stringWithFormat:NameFormat, IDPrefix, i+1];
        P1LOrderDispatcher *dispatcher = [OrderDispatcher sharedInstance];
        P1LBarInbox *barInbox = [dispatcher.barInboxMap objectForKey:barID];
        item.badgeNumber = [[barInbox ordersWithState:OrderState_New]count];
    }
    [super viewWillAppear:animated];
}


- (void)launcherView:(TTLauncherView*)launcher didSelectItem:(TTLauncherItem*)item 
{
    TTDPRINT(@"%@", item);
    TTNavigator *navigator = [TTNavigator navigator];
    [navigator openURLAction:[TTURLAction actionWithURLPath:item.URL]];
}

-(void)reloadLauncherView
{

    [overView setNeedsDisplay];//This doesn't work
}
@end

© Stack Overflow or respective owner

Related posts about iphone

Related posts about three20