我正在使用LeveyPopListView我改變了LeveyPopListView的大小以防止多次調用LeveyPopListView。但在我的應用程序,當我點擊太快顯示另一個LeveyPopListView重疊第一個LeveyPopListView。查看圖片以供參考(LeveyPopListView背景較暗,因爲有兩個重疊彈出)。LeveyPopListView多次調用
(主要頁面調用LeveyPopListView一) 創建了一個方法,用於創建LeveyPopListView
- (void) createLeveyPopList
{
NSInteger numberOfJobs = [[[[[self.FilterDictionary objectForKey:@"sub_slots"] valueForKey:@"company_group"] valueForKey:@"job_count"] objectAtIndex:[self.jobsTableView indexPathForSelectedRow].row] intValue];
NSString *jobs_name = xapp.jobName;
NSString *company_name;
if(numberOfJobs > 1)
{
isToDetail = false;
NSString *company_id = [[[[self.FilterDictionary objectForKey:@"sub_slots"] valueForKey:@"company_group"] valueForKey:@"company_id"] objectAtIndex:[self.jobsTableView indexPathForSelectedRow].row];
company_name = [[[[self.FilterDictionary objectForKey:@"sub_slots"] valueForKey:@"company_group"] valueForKey:@"company_name"] objectAtIndex:[self.jobsTableView indexPathForSelectedRow].row];
NSDictionary *specificCompany = [NSDictionary dictionaryWithObjectsAndKeys:company_id,@"company_id", nil];
if(specificCompany.count>0)
{
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:specificCompany
options:0 // Pass 0 if you don't care about the readability of the generated string
error:&error];
if (! jsonData)
{
NSLog(@"Got an error: %@", error);
}
else
{
strJsonStringFilter = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
}
allJobsDictionary = [NSJSONSerialization JSONObjectWithData:[network getData:[NSString stringWithFormat:@"get_all_job_offers?pt_id=%@&filter=%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"pt_id"], strJsonStringFilter]] options:kNilOptions error:nil];
jobsToDisplay=(NSArray*)[allJobsDictionary objectForKey:@"sub_slots"];
}
if(self.lplv != nil)
return;
self.lplv = [[LeveyPopListView alloc] initWithTitle:company_name options:jobsToDisplay jobName:jobs_name handler:^(NSInteger anIndex){
}];
self.lplv.delegate = self;
[self.lplv showInView:self.view animated:YES];
}
(位於LeveyPopListView類)爲我的關閉按鈕 代碼:
_close = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[_close addTarget:self
action:@selector(fadeOut)
forControlEvents:UIControlEventTouchUpInside];
(位於LeveyPopListView類) FADEOUT會見HOD:
- (void)fadeOut {
[UIView animateWithDuration:.35 animations:^{
self.transform = CGAffineTransformMakeScale(1.3, 1.3);
self.alpha = 0.0;
} completion:^(BOOL finished) {
NSLog(@"FINISH");
if (finished) {
[[NSNotificationCenter defaultCenter] removeObserver:self];
self.lplv.delegate = nil;
[self.lplv removeFromSuperview];
self.lplv = nil;
}
}];
}
這是我做的,我在shouldPerformSegueWithIdentifier中調用了createLeveyPopList。現在當我點擊關閉按鈕並調用crateLeveyPopList時,LeveyPopList不會被創建。這是因爲代碼m.lplv不是空的。我應該在哪裏調用removeLeveyPopList?請參閱關於按鈕方法的更新。 – aianLee 2015-04-06 10:33:53
更改[self removeFromSuperview];到[self.lplv removeFromSuperview]; (void)fadeOut {UIView animateWithDuration:.35動畫:{self.transform = CGAffineTransformMakeScale(1.3,1.3);} {self.transform = CGAffineTransformMakeScale(1.3,1.3); self.alpha = 0.0; }完成:^(BOOL完成){ NSLog(@「FINISH」); if(finished){[NSNotificationCenter defaultCenter] removeObserver:self]; [self.lplv removeFromSuperview]; } }]; } – 2015-04-06 10:38:00
hmm .. fadeOut方法在leveyPopListView類中被調用和創建..我改變了[self removeFromSuperview];到[self.lplv removeFromSuperview];仍然得到了相同的結果。 – aianLee 2015-04-06 10:50:30