我正在開發具有最新的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