-1
我不是Objective-C的初學者,但我是UITableViewCell的新手。如何使用解開按鈕在uitableviewcell上創建複選標記?
我想讓用戶能夠通過按下按鈕在TableViewCell上創建一個複選標記。這裏是我想出的代碼,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cellx = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(40, 5, 40, 40)];
[button setTitle:@"Button" forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor greenColor]];
[button setTintColor:[UIColor redColor]];
[button setTag:indexPath.row];
[cellx addSubview:button];
[cellx setIndentationLevel:1];
[cellx setIndentationWidth:45];
if (button.touchInside == YES)
{
NSLog(@"Button Pressed");
cellx.accessoryType = UITableViewCellAccessoryCheckmark;
[tableView reloadData];
}
return cellx;
}
而且該代碼似乎並沒有爲我工作。
任何想法?
'cellForRowAtIndexPath'僅在刷新/渲染單元格時調用。你需要捕獲你的按鈕,找出它在哪個單元上,在單元上設置一個屬性,記下它應該被檢查,然後刷新單元。 – Stonz2