我有一个UITableView
包含UISwitch
控件的单元格。它类似于下面显示的 iPhone 时钟应用程序中的表格视图......
(来源:epicself.com)
在我的应用程序的cellForRowAtIndexPath
方法中,我像这样创建并附加UISwitch
控件......
CGRect frameSwitch = CGRectMake(215.0, 10.0, 94.0, 27.0);
UISwitch *switchEnabled = [[UISwitch alloc] initWithFrame:frameSwitch];
[switchEnabled addTarget:self action:@selector(switchToggled:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = switchEnabled;
我的问题是,当用户切换开关并switchToggled
调用方法时,我怎么知道它属于哪个表格单元格?如果不知道它的上下文,我真的不能用它做很多事情。
非常感谢您的帮助!