我正在製作一個應用程序,我在uitableview單元格中使用複選框形式的按鈕。我正在改變該複選框上的圖像選擇和取消選擇狀態。現在我想,當我點擊另一個按鈕,然後表格視圖的所有單元格將被選中,單元格的所有複選框的圖像將改變?如何它可以在下面做的是我的示例代碼如何選擇按鈕上的所有uitableview單元點擊
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.lblArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *tableviewidentifier = @"cell";
TablecellTableViewCell *cell= [self.tblvie dequeueReusableCellWithIdentifier:tableviewidentifier];
if(cell==nil)
{
cell = [[TablecellTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableviewidentifier];
}
cell.lblImage.layer.cornerRadius=3.0f;
cell.lblImage.layer.borderWidth=1.0f;
cell.backgroundColor=[UIColor colorWithRed:(245/255.0) green:(245/255.0) blue:(245/255.0) alpha:1];
if ([self.checkimageArray containsObject:[self.lblArray objectAtIndex:indexPath.row]])
{
[cell.buttonCheckbox setImage:[UIImage imageNamed:@"check_box_ok.png"]
forState:UIControlStateNormal];
}
else
{
[cell.buttonCheckbox setImage:[UIImage imageNamed:@"uncheck.png"]
forState:UIControlStateNormal];
}
cell.buttonCheckbox.tag=indexPath.row;
[cell.buttonCheckbox addTarget:self action:@selector(checkButton:) forControlEvents:UIControlEventTouchUpInside];
cell.lblText.text=[self.lblArray objectAtIndex:indexPath.row];
return cell;
}
-(IBAction)checkButton:(UIButton *)sender
{
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tblvie];
NSIndexPath *indexPath = [self.tblvie indexPathForRowAtPoint:buttonPosition];
if ([self.checkimageArray containsObject:[self.lblArray objectAtIndex:indexPath.row]]) {
[self.checkimageArray removeObject:[self.lblArray objectAtIndex:indexPath.row]];
[email protected]"";
}
else {
[self.checkimageArray addObject:[self.lblArray objectAtIndex:indexPath.row]];
self.titleLabel.text=[self.lblArray objectAtIndex:sender.tag];
}
[self.tblvie reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationFade];
}
,這裏是我的按鈕,我點擊然後tableview中的所有單元格將選擇與所有細胞的圖像會改變,但它不工作
- (IBAction)selectbtns:(id)sender {
static NSString *tableviewidentifier = @"cell";
TablecellTableViewCell *cell= [self.tblvie dequeueReusableCellWithIdentifier:tableviewidentifier];
[cell.buttonCheckbox setImage:[UIImage imageNamed:@"check_box_ok.png"]
forState:UIControlStateNormal];
}
る嘗試:[UIImage的imageNamed:@ 「check_box_ok.png」 ] forState:UIControlStateNormal]; **添加行[yourtableview reloaddata] – 2014-12-02 05:09:46
是啊,但試過,但「無法加載」標識符爲「com.xxx.whyq的包中的一個筆尖引用的圖像」。checkboxwithTableview「 」 – 2014-12-02 05:15:31
清潔一次 – 2014-12-02 05:16:23