Запрос с условием Count

Есть еще один способ определить, когда был изменен масштаб (или любое другое свойство), - Key-Value-Observing (иначе KVO). Это особенно полезно, когда для нас не используется метод делегата. Из Apple docs :

Наблюдение за ключевыми значениями обеспечивает механизм, позволяющий объектам получать уведомления об изменениях в конкретных свойствах других объектов.

blockquote >

. Когда вы настраиваете свое представление в карте, добавьте этот фрагмент:

[self.mapView addObserver:self forKeyPath:@"camera.zoom" options:0 context:nil];

Теперь вам нужно реализовать метод -observeValueForKeyPath:ofObject:change:context:, чтобы фактически получить обратный вызов. Например:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {

if ([keyPath isEqualToString:@"camera.zoom"]) {

    // this static variable will hold the last value between invocations.
    static CGFloat lastZoom = 0;

    CGFloat currentZoom = [[object camera] zoom];

    if (!(fabs((lastZoom) - (currentZoom)) < FLT_EPSILON)) {

        //Zoom level has actually changed!
        NSLog(@"Zoom changed to: %.2f", [[object camera] zoom]);

    }

    //update last zoom level value.
    lastZoom = currentZoom;

    }
}

Не забудьте удалить наблюдателя в -dealloc или -viewDidDissapear в зависимости от ваших потребностей:

- (void)dealloc {

    [self.mapView removeObserver:self forKeyPath:@"camera.zoom"];

}

Счастливое кодирование: -)

0
задан Yogesh Sharma 13 July 2018 в 12:18
поделиться

4 ответа

Это то, что вы хотите?

SELECT h.Id, h.Date, t.Description,
       ( SUM(CASE WHEN h.TypeId <> 288 THEN 1 ELSE 0 END) +
         MAX(CASE WHEN h.TypeId = 288 THEN 1 ELSE 0 END)            
       ) as Counter
2
ответ дан Gordon Linoff 17 August 2018 в 12:59
поделиться
select sum(A.Counter), A.id FROM(

    SELECT h.Id, count(h.Id) as Counter
    FROM #test_history1 h
    INNER JOIN #test_history2 t on h.TypeId = t.Id
    WHERE h.Code != 288
    GROUP BY h.TypeId, h.Id

    union
    SELECT h.Id, 1 as Counter
    FROM #test_history1 h
    INNER JOIN #test_history2 t on h.TypeId = t.Id
    WHERE h.Code = 288
    GROUP BY h.TypeId, h.Id
    )A
    GROUP BY A.id
1
ответ дан Arjun k 17 August 2018 в 12:59
поделиться

Вы можете сделать:

select htyp.Id as TypeId, htyp.Description, 
       (case when htyp.Id = 288 then h.Counter1 else h.Counter end) as Counter
from HistoryType htyp cross apply 
    ( select count(*) as Counter, count(distinct h.TypeId) as Counter1
      from History h
      where h.TypeId = htyp.Id
    ) h;
0
ответ дан Yogesh Sharma 17 August 2018 в 12:59
поделиться
0
ответ дан Murali Mani 6 September 2018 в 09:17
поделиться
Другие вопросы по тегам:

Похожие вопросы: