我使用objective-c編程iPhone應用程序。版本是在iOS 8.1之後。在我的UITableViewCell中有一些UITableViewRowAction,我點擊UITableViewRowAction之一後發佈請求,如果成功,我想更新按鈕(UITableViewRowAction)無效,以便它不能再次點擊。請幫助我,這很重要,但我沒有辦法解決。如何更新UITableViewRowAction中的按鈕?
如圖所示: 這是細胞,我們可以向左滑動
我使用objective-c編程iPhone應用程序。版本是在iOS 8.1之後。在我的UITableViewCell中有一些UITableViewRowAction,我點擊UITableViewRowAction之一後發佈請求,如果成功,我想更新按鈕(UITableViewRowAction)無效,以便它不能再次點擊。請幫助我,這很重要,但我沒有辦法解決。如何更新UITableViewRowAction中的按鈕?
如圖所示: 這是細胞,我們可以向左滑動
後向左滑動
,我們可以看到三個按鈕,我想你是需要使用UITableView代理方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
這個按鈕並沒有被UITableViewCell添加,它被添加爲UITableViewRowAction,你會在幻燈片後看到它Cell left – user3196823
使用didSelectRowAtIndexPath
方法發佈您的請求。
在您的實現:
{
int selectedIndex;
}
然後:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
selectedIndex=indexPath.row;
YourCell *cell = (YourCell *)[tableView cellForRowAtIndexPath:selectedIndex];
if(cell.cellEnabled)
{
//Your request goes here...
}
else
{
//The cell is disabled..
}
}
cellEnabled是,你必須設置爲「YES」上的成功響應您的cell.h文件內聲明的布爾值請求。
ie;在獲得成功響應後,添加以下代碼
YourCell *cell = (YourCell *)[tableView cellForRowAtIndexPath:selectedIndex];
cell.cellEnabled=YES;
我不想讓UITableViewCell無效,我只想讓按鈕(UITableViewRowAction)無效 – user3196823
你在說哪個按鈕?它是否在單元格內?如果是這樣,在獲得成功響應時,添加以下代碼。 YourCell * cell =(YourCell *)[tableView cellForRowAtIndexPath:selectedIndex]; cell.button.enabled = NO;如果可能的話, – abhi1992
上傳圖片。 – abhi1992
您需要爲每個單元手動維護一個狀態。 如果用戶點擊您的操作按鈕,保存該值。 當用戶再次滑動單元格時,只需更改該按鈕的背景顏色,不要爲其寫入動作塊。 – iOSEnthusiatic