如何在Pages-Array中添加它后删除一个项目?
我在这里试了一下:
launcherView.pages = [NSArray arrayWithObjects:
[NSArray arrayWithObjects:
[self launcherItemWithTitle:@"Pers. Starts."
image:@"bundle://animexx-72.png"
URL:@"tt://startseite"],
[self launcherItemWithTitle:@"ENS"
image:@"bundle://animexx-72.png"
URL:@"tt://ens"],
[self launcherItemWithTitle:@"Kontakte"
image:@"bundle://animexx-72.png"
URL:@"tt://kontakte"],
[self launcherItemWithTitle:@"Einstellungen"
image:@"bundle://animexx-72.png"
URL:@"tt://einstellungen"],
[self launcherItemWithTitle:@"Admin"
image:@"bundle://animexx-72.png"
URL:@"tt://admin"]
, nil]
, nil];
//Check if ENS-Admin enabled
if ([SelfViewHandler IsENSAdminSet])
{
TTLauncherItem* item;
item = [launcherView itemWithURL:@"tt://admin"];
[launcherView removeItem:item animated:false];
}
但物品仍在那里。 (If-Clause为true,在Debugger和Breakpoint中检查它)
答案 0 :(得分:1)
对象item = [launcherView itemWithURL:@"tt://admin"]
实际上并不存在于您的TTLauncherView
中,并且因此而未被删除。
每个对象在创建时都会获得引用,因此在创建pages数组时添加的对象和在if语句中创建的对象是不同的。
要从TTLauncherView
中删除对象,您需要引用它。你可以这样做:
TTLauncherItem* item = [self launcherItemWithTitle:@"Admin"
image:@"bundle://animexx-72.png"
URL:@"tt://admin"]
launcherView.pages = [NSArray arrayWithObjects:
[NSArray arrayWithObjects:
[self launcherItemWithTitle:@"Pers. Starts."
image:@"bundle://animexx-72.png"
URL:@"tt://startseite"],
[self launcherItemWithTitle:@"ENS"
image:@"bundle://animexx-72.png"
URL:@"tt://ens"],
[self launcherItemWithTitle:@"Kontakte"
image:@"bundle://animexx-72.png"
URL:@"tt://kontakte"],
[self launcherItemWithTitle:@"Einstellungen"
image:@"bundle://animexx-72.png"
URL:@"tt://einstellungen"],
adminLauncherItem
, nil]
, nil];
//Check if ENS-Admin enabled
if ([SelfViewHandler IsENSAdminSet])
{
[launcherView removeItem:adminLauncherItem animated:false];
}
有一个函数可以根据URL删除启动项,比如
- (void)removeItemWithURL:(NSURL*)url animated:(BOOL)animated {
(但还没有:-))