我有一個自定義的UIButton我TableViewCell通過:自定義的UIButton中的UITableViewCell - 刪除不工作
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *ident = @"indet";
cell = [tableView dequeueReusableCellWithIdentifier:ident];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:ident] autorelease];
}
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame: CGRectMake(230.0f, 7.5f, 43.0f, 43.0f)];
[button setImage:[UIImage imageNamed:@"check_bak.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(removeEntry) forControlEvents:UIControlEventTouchUpInside];
button.tag = [indexPath row];
[cell addSubview:button];
cell.textLabel.text = [myArray objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:20.0];
cell.textLabel.shadowColor = [UIColor whiteColor];
cell.textLabel.shadowOffset = CGSizeMake(0,1);
return cell;
}
我宣佈我的.h爲removeEntry功能indexPath。
removeEntry:
[myArray removeObjectAtIndex:indexPath.row];
[myTable reloadData];
myArray的是一個的NSMutableArray。
這種方式無法正常工作。
每次我在indexPath.row刪除一個條目,它都會刪除一個條目。但是錯誤的。它總是一個條目上面被刪除。即使我做indexPath.row + 1/-1。
還有別的辦法嗎?按鈕應該留在單元格中。
我希望這是可以理解的,對不起,我是德國人。 :)
你如何將'indexPath'傳遞給你的'removeEntry'方法,以及你如何調用它? – benwong 2011-03-28 22:55:32