gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:57:57 25 4
gpt4 key购买 nike

我有一个 TTLauncherView 和一些 TTLauncherItems。这些显示角标(Badge),代表来自网络的消息。我在 viewWillAppear: 中设置了角标(Badge),因此如果我切换到另一个 View 然后返回,则会显示正确的角标(Badge)。但是我想在收到消息后立即更新角标(Badge)。

在 TTLauncherView 上调用 setNeedsDisplay 没有帮助?

如何刷新 TTLauncherView

在我的 MessageReceiver 类中,我这样做:

TTNavigator* navigator = [TTNavigator navigator];

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

我的 TTViewController 派生的 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

最佳答案

我在 AppDelegate 上用 LauncherView 注册了我的 Controller 。在我的消息传递类中,我调用 [appDelegate reloadLauncherView]; 再次调用它

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

在包含 LauncherView 的 Controller 上。

关于objective-c - TTLauncherItem : change badge immediately (or: how to refresh TTLauncherView),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2999082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com