我正在製作一個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