我正在制作一个iphone应用程序。在应用程序的一个视图中,我实现了表视图。在每个表格视图单元格中,我放置了一个或两个按钮。现在我希望每当我点击按钮它给我的细胞的价值。如果有人对此有所了解,请告诉我,我该怎么做?桌面单元格值
我已经实现为显示按钮的代码是:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [rangetime objectAtIndex:indexPath.row];
NSString *checkstatus = [finalstatusarray objectAtIndex:indexPath.row];
if ([checkstatus isEqualToString:@"YES" ])
{
UIButton *submitbutton1 = [UIButton buttonWithType:UIButtonTypeCustom];
submitbutton1.tag=1;
submitbutton1.frame = CGRectMake(200, 4, 28, 29);
UIImage * btnImage1 = [UIImage imageNamed:@"yes.png"];
[submitbutton1 setImage:btnImage1 forState:UIControlStateNormal];
cell.accessoryView = submitbutton1;
[submitbutton1 addTarget:self action:@selector(updatestatus) forControlEvents:UIControlEventTouchUpInside];
}
else if ([checkstatus isEqualToString:@"NO" ])
{
UIButton *submitbutton2 = [UIButton buttonWithType:UIButtonTypeCustom];
submitbutton2.tag = 2;
submitbutton2.frame = CGRectMake(200, 4, 28, 29);
UIImage * btnImage1 = [UIImage imageNamed:@"no.png"];
[submitbutton2 setImage:btnImage1 forState:UIControlStateNormal];
[submitbutton2 addTarget:self action:@selector(updatestatus) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = submitbutton2;
}
else if ([checkstatus isEqualToString:@"s" ])
{
UIButton *submitbutton1 = [UIButton buttonWithType:UIButtonTypeCustom];
submitbutton1.tag = 1;
submitbutton1.frame = CGRectMake(255, 5, 28, 29);
UIImage * btnImage1 = [UIImage imageNamed:@"no.png"];
[submitbutton1 setImage:btnImage1 forState:UIControlStateNormal];
[cell addSubview:submitbutton1];// = submitbutton1;
[submitbutton1 addTarget:self action:@selector(updatestatus) forControlEvents:UIControlEventTouchUpInside];
UIButton *submitbutton2 = [UIButton buttonWithType:UIButtonTypeCustom];
submitbutton2.tag = 2;
submitbutton2.frame = CGRectMake(285, 5, 28, 29);
UIImage * btnImage2 = [UIImage imageNamed:@"yes.png"];
[submitbutton2 setImage:btnImage2 forState:UIControlStateNormal];
[cell addSubview:submitbutton2];
[submitbutton2 addTarget:self action:@selector(updatestatus) forControlEvents:UIControlEventTouchUpInside];
}
return cell;
}
Thanku非常多。
非常感谢...它工作正常.. –
它是我的荣幸... – SJS