When you create your SubViewController, the variable sub
that points to it is local to the addSubViewButton:
method and will be released when that method ends. You need to keep a strong reference to that controller so that it's not deallocated before you use it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…