Essentially, when you, as a person with ILR, return to the UK after a time abroad, the immigration officer has to be content that you are still resident (settled) in the UK and are returning to continue that residence (settled state). Normally, a period of 2 years or more away from the UK is taken as a cut-off point after which it is considered that residency is not maintained. However, that is not a hard-and-fast rule: it is possible (although in practice it must be relatively unusual) to lose ILR after shorter periods away if you are no longer
living in the UK - so you can't, in theory at least and increasingly probably in practice, maintain ILR by making short visits to the UK every year or two - and it is possible to retain ILR even if you are away for longer than 2 years in certain circumstances (although in such cases pre-entry clearance may be required).
If the immigration officer at the point of entry is not satisfied that you are still resident in the UK, then yes, the ILR can be revoked there and then.
The
immigration rules can be consulted on-line; the
most relevant part says:
Returning Residents
18. A person seeking leave to enter the United Kingdom as a returning resident may be admitted for settlement provided the Immigration Officer is satisfied that the person concerned:
(i) had indefinite leave to enter or remain in the United Kingdom when he last left; and
(ii) has not been away from the United Kingdom for more than 2 years; and
(iii) did not receive assistance from public funds towards the cost of leaving the United Kingdom; and
(iv) now seeks admission for the purpose of settlement.
19. A person who does not benefit from the preceding paragraph by reason only of having been away from the United Kingdom too long may nevertheless be admitted as a returning resident if, for example, he has lived here for most of his life.
19A. Where a person who has indefinite leave to enter or remain in the United Kingdom accompanies, on a tour of duty abroad, a spouse, civil partner, unmarried partner or same-sex partner who is a member of HM Forces serving overseas, or a permanent member of HM Diplomatic Service, or a comparable United Kingdom-based staff member of the British Council, or a staff member of the Department for International Development who is a British Citizen or is settled in the United Kingdom, sub-paragraphs (ii) and (iii) of paragraph 18 shall not apply.