我在自定義UITableViewCell
中定義了兩個不同的UIButton
。該定製UITableViewCell
用於UIViewController
內的UITableView
。現在我想單擊更改UIButton
的圖像。我用protocoll和delegate嘗試了它,但它不起作用。任何想法如何我可以做到這一點?單擊自定義UITableViewCell時更改UIButton圖像
0
A
回答
1
在你cellforowatindexpath方法
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier;
CellIdentifier = @"Cell";
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UIButton *btn = (UIButton *)[cell viewWithTag: 1]; // or however you are initializing the button
[btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
-(void)btnClicked:(id)sender
{
UIButtin *btn = (UIButton *)sender;
[btn setImage:[UIImage imageNamed:@"click.png"] forState:UIControlStateNormal];
}
0
當你點擊你的按鈕重新加載該特定的單元格,以及你在哪裏製作自定義單元格時,在委託部分定義委託並更改背景圖片。
願這幫助你。
相關問題
- 1. 單擊更改UIbutton圖像
- 2. 自定義UITableViewCell UIButton
- 3. 單擊時自定義UITableViewCell佈局更改(僅限iOS7)
- 4. 多次點擊時更改UIButton圖像
- 5. 如何在UITableviewCell中單擊時更改UIButton的背景顏色?
- 6. 自定義UIButton圖像iOS
- 7. UIButton背景圖像點擊更改
- 8. 自定義UITableViewCell按鈕單擊
- 9. 使用自定義UIButton刪除UITableViewCell
- 10. 用UIButton自定義UITableViewCell:哪個按鈕被點擊過?
- 11. 更改單元格內的UIButton圖像
- 12. 更改uitableviewcell中的自定義accessoryView?
- 13. UITableViewCell自定義 - 更改背景
- 14. UIButton的自定義圖像和框架
- 15. iPhone 2G上的自定義UIButton圖像
- 16. 自定義圖像的子類UIButton?
- 17. 如何更改UIButton中的UIButton背景圖像點擊ios
- 18. UIImageView模板圖像色彩在UITableViewCell上的更改單擊
- 19. 我想在點擊它時更改UIButton圖像
- 20. 無法更改選定狀態的自定義uiButton的背景圖像
- 21. 更改圖像時,點擊imagebutton項目自定義列表視圖android
- 22. 更改點擊自定義屬性的所有圖像
- 23. 單擊其他UIButton時更改UIButton的UIImage
- 24. UITableViewCell自定義,更新UILabel
- 25. 如何在自定義UITableViewCell內按下UIButton時獲取indexPathForSelectedRow
- 26. 更改預定義的UITableViewCell設計的圖像大小「基本
- 27. UITableViewCell中的UIButton面臨圖像更改問題,同時tableview滾動
- 28. 基於視圖更改自定義UITableViewCell高度
- 29. 自定義UITableViewCell在滾動時更改indexPath?
- 30. Android:如何更改GridView圖像,同時單擊圖像查看
你能告訴你已經嘗試的代碼? – Jasper
我已刪除代碼..可能您可以添加一些代碼示例或鏈接。 – Daniela