开发者

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] initW开发者_如何学运维ithTitle: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


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.


I was having a very similar problem today, (modifying a TTLauncherItem, and not seeing my changes directly) and was able to solve it by making a call to [myLauncherView layoutSubviews]; BEFORE I modified the TTLauncherItem. I actually tracked it down in the code, and this was because layoutSubviews will re-create the LauncherView's _buttons array (which is what needed to happen, in my case).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜