Warning Attempt to present on which is already presenting null
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
This UIKit warning appears when code tries to present a new view controller while the current presenter is already presenting another controller or is not in a valid presentation state. It is common in async flows, repeated button taps, and lifecycle timing mistakes. The fix is usually to serialize presentation attempts and present from the correct top controller.
Core Sections
What the Warning Means in Practice
A typical warning message says the app attempted to present controller B from controller A while A is already presenting something else. UIKit blocks the second presentation to avoid inconsistent view hierarchy state.
Frequent causes:
- triggering
presenttwice before first animation finishes - calling
presentfrom a controller not currently in window hierarchy - presenting during
viewDidLoadbefore appearance lifecycle completes - competing async callbacks that both attempt navigation
Treat this warning as a state management issue, not as a random UIKit bug.
Present From the Top Most Visible Controller
In complex apps with tabs, navigation stacks, and modals, the safest presenter is the top visible controller. Build a helper and centralize modal presentation calls.
Using one helper avoids scattered presenter assumptions across view models and coordinators.
Guard Against Duplicate Presentation Calls
Before presenting, verify no modal is already active and optionally debounce repeated taps.
This pattern prevents duplicated alerts caused by rapid retries or parallel network callbacks.
Coordinate Async Flows and Lifecycle Timing
Presentation triggered from async work should be routed to main thread and checked against current lifecycle state. Presenting during transition phases is fragile.
Checking window attachment prevents presentation from off screen controllers after navigation changes.
Use a Navigation Coordinator for Large Apps
When several modules can trigger modals, coordinator based presentation avoids race conditions. The coordinator owns a serial queue of navigation intents and decides what to show next.
Simple coordinator idea:
- one presentation entry point
- one active modal at a time
- queue or drop duplicate intents by key
This architecture removes modal logic from random callbacks and makes warnings significantly less frequent.
Debugging Checklist
When warning appears in logs:
- Add temporary logging before every
presentcall. - Log current controller, presented controller, and thread.
- Reproduce with UI test that taps rapidly.
- Confirm transitions finish before next presentation.
You can also set symbolic breakpoints on UIViewController presentation methods to capture the second conflicting call site immediately.
Common Pitfalls
- Presenting from controllers that are no longer visible.
- Triggering multiple
presentcalls from concurrent async callbacks. - Showing modals in early lifecycle methods before appearance.
- Ignoring
presentedViewControllerstate checks. - Spreading modal logic across many classes without coordination.
Summary
- The warning indicates overlapping or invalid modal presentation attempts.
- Present from the top visible controller and centralize logic.
- Guard duplicate calls with state checks and debouncing.
- Synchronize async callbacks with main thread and lifecycle checks.
- Use coordinator style navigation for complex modal flows.
Related reading
- Warning Attempt to present on whose view is not in the window hierarchy - swift
- Warning Failed child context type Invalid child context ''virtualizedCell.cellKey'' of type ''number'' supplied to ''CellRenderer'', expected ''string''
- Warning Found conflicts between different versions of the same dependent assembly
- Warning Kotlin plugin version is not the same as library version but it is
- Warning The Copy Bundle Resources build phase contains this target's Info.plist file
- Warning the user/local/mysql/data directory is not owned by the mysql user
- Warning tried to deallocate nullptr when using tensorflow eager execution with tf.keras
- WARNING UNPROTECTED PRIVATE KEY FILE when trying to SSH into Amazon EC2 Instance
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.