Chris
Chris

Reputation: 17

determine if an array element contains an image

Hi If you have an array that stores images and text then displays the content in a random manner how can you check to know that the element about to be retrieved contains an image or text so that if an image I display a UIMageView and if text I display a UILabel

thanks.

Upvotes: 0

Views: 176

Answers (1)

Wienke
Wienke

Reputation: 3733

Assuming your text is always an instance of NSString and your images are always instances of UIImage:

for (id obj in mixedArray) {
    if ([obj isKindOfClass:[NSString class]])
         // display via UILabel
    else if ([obj isKindOfClass:[UIImage class]])
         // display via UIImageView
}

Upvotes: 3

Related Questions