我有幾個文本域,每個都帶有標籤,我想單獨添加到數組中。在添加之前,我需要確定它來自哪個字段。我想對它們全部使用相同的方法,而不是爲每個文本字段設置一個方法。OBJ C - 如何從發件人獲取文本字段名稱
是否可以從發件人獲取文本字段的變量名稱?如果他們是按鈕,我可以使用[sender currentTitle],但我不知道如何從文本字段獲取標識符。
我想到的是這樣的:
- (void)makeItSo:(id)sender
{
NSString * senderName = (UITextField*)[sender stringValue] ;
if ([senderName isEqual: @"name"])
-- add name to array
else if ([senderName isEqual: @"address"])
-- add address to array
}
爲什麼說最好不要使用實例變量? – 2013-03-22 22:54:15
@AaronBrager不,你最好不要獲取實例變量的名字。 – 2013-03-22 22:54:41