我有一個學生類:如何獲得NSPopUpButton選定的對象?
@interface student : NSObject{
NSString *name;
NSDate *date;
}
和我有一個NSMutableArray的學生名單,並且我把它綁定到NSPopUpButton這樣
內容:studentArray,arrangedObjects 含量值:studentArray ,arrangedObjects,名
我可以讓學生對象是這樣的:
-(IBAction)studentPopupItemSelected:(id)sender
{
NSPopUpButton *btn = (NSPopUpButton*)sender;
int index = [btn indexOfSelectedItem];
student *std = [studentArray objectAtIndex:index];
NSLog(@"%@ => %@", [std name], [std date]);
}
有沒有什麼辦法可以直接從NSPopUpButton獲取學生對象?像:
NSPopUpButton *btn = (NSPopUpButton*)sender;
student *std = (student *)[btn objectValueOfSelectedItem];
出於好奇,什麼是觸發'IBAction'列出? –