我在自定義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. 更改自定義UITableViewCell
- 7. 自定義UIButton圖像iOS
- 8. 自定義UIButton與圖像
- 9. 蘋果ipad iphone UITableViewCell與UIButton:更改按鈕圖像按鈕單擊?
- 10. 自定義UIButton不會更改其圖像
- 11. UIButton背景圖像點擊更改
- 12. 自定義UITableViewCell按鈕單擊
- 13. 在自定義UITableViewCell中訪問UIButton
- 14. 我想添加自定義UIButton到UITableViewCell
- 15. setImage:forState:用於UIButton的自定義UITableViewCell
- 16. UIButton未在自定義UITableViewCell中響應
- 17. 使用自定義UIButton刪除UITableViewCell
- 18. 用UIButton自定義UITableViewCell:哪個按鈕被點擊過?
- 19. 更改自定義UIButton的狀態
- 20. 更改單元格內的UIButton圖像
- 21. 自定義UITableViewCell不響應更改
- 22. 更改uitableviewcell中的自定義accessoryView?
- 23. UITableViewCell自定義 - 更改背景
- 24. 我無法從自定義UITableViewCell中刪除自定義UIButton
- 25. 單擊按鈕時更改URL圖像
- 26. UIButton的自定義圖像和框架
- 27. iPhone 2G上的自定義UIButton圖像
- 28. UIButton的自定義陰影圖像
- 29. 自定義UIButton嵌入圖像大小
- 30. 自定義圖像的子類UIButton?
你能告訴你已經嘗試的代碼? – Jasper
我已刪除代碼..可能您可以添加一些代碼示例或鏈接。 – Daniela