我在故事板中定义了三个原型单元UISegmentedControl
,每个单元都包含一个小部件。我有两种标准可以向用户展示;一个是[ON|OFF]
另一个是[1|2|3|4]
。我需要以编程方式设置每个小部件的文本,因此我Tag
在情节提要中设置小部件,以便使用[cell viewWithTag:XX]
. 问题是,我所有的UISegmentedControl
小部件都连接到同一个侦听器,我无法判断用户正在打开或关闭哪些标准。我已经看到Tag
设置为行号的值,cellForRowAtIndexPath
但我已经Tag
在情节提要中使用了。我怎样才能知道在我的侦听器中正在与哪一行进行交互?
更新:添加了代码片段
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *retcell;
NSInteger thisrow = indexPath.row;
// retrieve the items which should be printed for this
// row. set text on widget depending on item type
OBJ_Items *items = [mCriteria objectForKey:thisrow];
if ([items.Type isEqualToString:YESNO])
{
retcell = [tableView dequeueReusableCellWithIdentifier:@"yesno"];
// get a handle to the widget in this cell in order to access it's Text property
UISegmentedControl *yesno = (UISegmentedControl *)[retcell viewWithTag:200];
// .. set text for yesno segments
// save the row numer to this object's tag so we can retrieve the item object
// on click
[yesno setTag:thisrow];
}
if ([items.Type isEqualToString:SETTING])
{
retcell = [tableView dequeueReusableCellWithIdentifier:@"setting"];
UISegmentedControl *setting = (UISegmentedControl *)[retcell viewWithTag:201];
// set text for segments...
[setting setTag:thisrow];
}
return (retcell);
}