【发布时间】:2012-03-06 07:34:23
【问题描述】:
我正在使用最新的 SDK 和 XCode 4.2 开发一个 iOS 4 应用程序。
我有一个 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;
}
}
}
...
}
当用户触摸该按钮内部时,我如何知道单击的单元格是在哪个部分和哪一行?
【问题讨论】:
-
您可以为该按钮设置标签。通过使用该标签号,您可以找出单击了哪个按钮。
标签: ios uitableview uibutton