Venkat1282 Venkat1282 - 2 months ago 17
Objective-C Question

How to check if subview is button or not

I am developing an application. In that I get all subviews of UITableViewCell.

The code for this one is:

(void)listSubviewsOfView:(UIView *)view {

// Get the subviews of the view
NSArray *subviews = [view subviews];

// Return if there are no subviews
if ([subviews count] == 0) return;

for (UIView *subview in subviews) {

NSLog(@"%@", subview);

// List the subviews of subview
[self listSubviewsOfView:subview];
}
}


But my problem is how to find out button from that subviews list. Please tell me how to solve this one.

Answer Source

You can iterate through all subviews like this.

for (id subview in subviews) {
   if ([subview isKindOfClass:[UIButton class]]) {
      //do your code
   }
}