2011-09-08 76 views

回答

2

是的!

假設你把代碼中的UIView子類,你可以抓住子視圖數組...

NSArray *sbviews = [self subviews]; 
NSMutableArray *textFields; //placeholder for your UITextField subclassed objects. 

//enumerate through the subview collection and only add objects to the textFields array that are UITextField objects. 
for (id anObject in sbviews) { 
    if([anObject isKindOfClass: [UITextField class]]){ 
     [textField addObject: anObject]; 
    } 
} 

文本字段數組現在包含有實物類的UITextField的所有對象...

+0

正是我在找的 - 非常感謝你 – svjim

0

您的UIView類有一個子視圖數組,列出您添加到它的所有子視圖。您可以遍歷數組並查找UITextField對象的實例(而不是類)。

for (UITextField* textField in [someView subviews]) { 
    if ([textField isKindOfClass:[UITextField class]]) { 
     // found one, textField really is a UITextField 
    } 
} 
+0

非常感謝 – svjim

相關問題