ios - UITableViewRowAction - 一个的背景颜色影响另一个
<p><p>我的源代码中有 3 个 <code>UITableViewRowAction's</code>,如下所示:</p>
<pre><code>- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView
editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(messagePremission)
{
messageAction = handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
}];
messageAction.backgroundColor = ;
}
else
{
messageAction = handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
}];
messageAction.backgroundColor = ;
}
if(editPermission)
{
editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:NSLocalizedString(@"edit_swipe", nil) handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
}];
editAction.backgroundColor = ;
}
else
{
editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:NSLocalizedString(@"edit_swipe", nil) handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
}];
editAction.backgroundColor = ;
}
if(cancelPermission)
{
cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Cancel"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
}];
cancelAction.backgroundColor = ;
}
else
{
cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Cancel"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
}];
cancelAction.backgroundColor = ;
}
;
;
;
return arrButtons;
}
</code></pre>
<p>在每个 <code>if</code> 条件中,一个按钮被创建为启用,而在相应的 <code>else</code> 条件中,一个按钮被创建为禁用。 </p>
<p>然而,<code>messageAction</code> 的<code>backgroundColor</code> 会影响其他两个,当只有<code>messageAction</code> 被启用而其他两个被禁用时。 </p>
<p>为了确认这一点,我通过将 <code>cancelAction</code> 放在首位来颠倒按钮的显示顺序。这样,取消按钮的 <code>backgroundColor</code> 会影响其他两个。</p>
<p>如何修复每个按钮的可视化 od <code>backgroundColor</code> 属性?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>覆盖 <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/#//apple_ref/occ/intfm/UITableViewDelegate/tableView:editActionsForRowAtIndexPath:" rel="noreferrer noopener nofollow"><code>editActionsForRowAtIndexPath</code></a> tableview 委托(delegate)方法如下:-</p>
<pre><code>-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *messageButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Message" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
NSLog(@"Action to perform with messageButton Button");
}];
UIColor *messageColor= if(messagePremission == true) ? :
;
messageButton.backgroundColor = messageColor;
UITableViewRowAction *editButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Edit" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
NSLog(@"Action to perform with editButton Button!");
}];
UIColor *editColor= if(editPermission == true) ? :
;
editButton.backgroundColor = editColor;
UITableViewRowAction *cancelButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Cancel" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
NSLog(@"Action to perform with cancelButton");
}];
UIColor *cancelColor= if(cancelPermission == true) ? :
;
cancelButton.backgroundColor = cancelColor;
return @;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - UITableViewRowAction - 一个的背景颜色影响另一个,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39121250/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39121250/
</a>
</p>
页:
[1]