Two goods are substitutes when using more of one good replaces the use of another good. An example is Pepsi and Coca-Cola. Two goods are complementary when using more of one good increases the use of another. An example is bread and jam.
When the price of a substitute increases, the quantity demanded decreases by the law of demand (negatively sloped demand curve). As we know, when the price of a substitute (bananas) goes up, you want to buy less of that good, so you'll want to substitute it with another similar good (apples). The substitution results in an increased demand of the substitute good (apples). The price of apples stay the same so the only way to show an increased quantity demanded of that good is to shift the entire demand curve to the right. Therefore, an increase in the price of a bananas increases the demand for apples.
When the price of a complementary good increases, the quantity of the complementary good demanded decreases by the law of demand. In this case, an decreased quantity of apple pies demanded would mean that consumers would buy less apples because they are complementary. The price of apples must stay the same so the only way to show a decreased demand in quantity is to shift the entire demand curve to the left. Therefore, an increase in the price of apple pies decrease the demand for apples.