[英]double cell button action
我有一個UITableView,其中有一個針對UITableViewCell的xib文件。
在UITableViewCell上,我添加了2個單元格數據-因為我想實現兩列樣式。 因此無法修改。 該單元有點復雜,它還有更多的組件,我想處理按鈕UIControlEventTouchUpInside事件的動作。 它將在任務競賽后下載一些內容並需要將按鈕文本從“下載”更改為“查看”,例如。
如果我不處理多線程,異步的東西,但是需要的話,它將解決。 因此,我需要將按鈕和索引傳遞給action方法,或者為按鈕設置屬性(在Java中很容易),但找不到它。
一半的代碼如下所示:
[buttonAction addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
並且需要這樣的東西:
-(void)buttonPressed:(UIButton*)button index: (int) index
{
}
在另一個問題中,索引是通過buttonAction.tag = index
傳遞的,但是如果我更改該屬性,那么我認為它不會起作用
UIButton * buttonAction =(UIButton *)[cell viewWithTag:205]; 在發表聲明
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
有什么建議如何處理這種情況?
您可以UIButton
類,並具有所需所有信息的屬性。 然后使用@selector(buttonPressed:)
將操作添加到TouchUpInside的按鈕中
-(void)buttonPressed:(YourCustomButton *)sender // or id and then you check it's class and cast to your custom button class
{
// work with sender.yourProperty
}
編輯
[button setTitle:@"Download" forState:UIControlStateNormal];
[button setTitle:@"View" forState:UIControlStateReserved];
然后根據您的標題進行工作: button.currentTitle
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.