objective-cioscocoa-touchthree20

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


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

Solution

  • I register my Controller with the LauncherView at the AppDelegate. In my messaging class I call [appDelegate reloadLauncherView]; that again will call this

    -(void)reloadLauncherView
    {
        [self viewWillAppear:NO ];
    }
    

    on the Controller that contains the LauncherView.