我正在开发具有最新的SDK和的XCode 4.2的iOS 4的应用程序。用UIButton自定义UITableViewCell:哪个按钮被点击过?
我有一个UITableView
用切片和定制UITableViewCell
。每个单元格都有一个UIButton,并且所有这些按钮具有相同的目标UIControlEventTouchUpInside
。
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* cellIdentifier = @"CalendarCell";
CalendarEventCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CalendarEventCell" owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[CalendarEventCell class]])
{
cell = (CalendarEventCell *)currentObject;
[cell.addToCalendarButton addTarget:self action:@selector(addEventToiCal) forControlEvents:UIControlEventTouchUpInside];
break;
}
}
}
...
}
当用户触摸该按钮内,我怎么能知道哪个部分和行是已单击单元格?
您可以能够为这个按钮设置标签。通过使用该标签号码,您可以找出哪个按钮被点击。 – Ganesh 2012-03-06 07:42:43
看看这里:http://stackoverflow.com/questions/510393/how-to-pass-a-variable-to-a-uibutton-action – pkyeck 2012-03-06 07:45:56