Tôi đang cố gắng để tìm chọn UITableViewCell
như sau:iOS, Cách tìm hàng đã chọn của UITableView?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
if ([indexPath row] == [tableView cellForRowAtIndexPath:indexPath.row]) // i want to place value of selected row to populate the buttons
//([indexPath row] == 0)
//(indexPath.row == ![self cellIsSelected:indexPath])
{
UIButton *AddComment = [UIButton buttonWithType:UIButtonTypeCustom]; // custom means transparent it takes shape same with backgroup image
[AddComment addTarget:self
action:@selector(TestBtns:)
forControlEvents:UIControlEventTouchDown];
// [AddComment setTitle:@"1" forState:UIControlStateNormal];
AddComment.frame = CGRectMake(9.0, 128.0, 96.0, 26.0);
[cell.contentView addSubview:AddComment];
UIImage *buttonAddComment = [UIImage imageNamed:@"addcomment.png"];
[AddComment setBackgroundImage:buttonAddComment forState:UIControlStateNormal];
[cell.contentView addSubview:AddComment];
}
Làm thế nào để đạt được điều này, bạn có thể xin vui lòng hướng dẫn cho tôi, nơi tôi đang làm sai lầm.
đâu ** didselectrowatindexpath ** phương pháp ??? –
bạn muốn tinh chỉnh ô đã chọn của UITableview ở đâu ..? tại ** didselectrowatindexpath ** hoặc nút TouchUiInside Method? –
Vui lòng kiểm tra dòng "if ([dòng indexPath] == [tableView cellForRowAtIndexPath: indexPath])". Ở đây bạn đang so sánh một NSInteger với một UITableViewCell! – AlexVogel