我该如何解决这个问题?我是一名新编码员。谢谢
我收到以下错误:
"无法分配类型为' Bool'"的不可变表达式
当我尝试设置&#34; isSelected&#34;到<div class="container">
<div class="row">
<div class="door">
<?php query_posts(array('post_type'=>'door_function', 'posts_per_page'=>4, 'order' => 'ASC', 'paged' => $paged,)); ?>
<?php if(have_posts()) { while(have_posts()) { the_post(); ?>
<div class="col-sm-3 text-center">
<span class="door_link"><a href="#<?php the_title(); ?>"><?php the_title(); ?></a></span>
</div>
<?php } }?>
</div>
</div>
</div>
<?php query_posts(array('post_type'=>'door_function', 'posts_per_page'=>4, 'order' => 'ASC', 'paged' => $paged,)); ?>
<?php if(have_posts()) { while(have_posts()) { the_post(); ?>
<div class="door_function" id="<?php the_title(); ?>">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="outer" style="overflow:hidden;">
<div id="sync1" class="owl-carousel">
<?php if( have_rows('images') ):
while ( have_rows('images') ) : the_row(); ?>
<div class="item">
<img src="<?php the_sub_field('post_image');?>"/>
</div>
<?php endwhile;
endif;
?>
</div>
<div id="sync2" class="owl-carousel">
<?php if( have_rows('images') ):
while ( have_rows('images') ) : the_row(); ?>
<div class="item">
<img src="<?php the_sub_field('post_image');?>"/>
</div>
<?php endwhile;
endif;
?>
</div>
</div>
</div>
<div class="col-md-1">
</div>
<div class="col-md-7">
<h3><?php the_field('subtitle'); ?> </h3>
<h2><?php the_field('title'); ?> </h2>
<a href="https://www.youtube.com/watch?v=<?php the_field('video_link'); ?>">PLAY THE VIDEO</a>
<p><?php the_content(); ?></p>
</div>
</div>
</div>
</div>
<?php } }?>
和false
true
答案 0 :(得分:2)
您收到此错误,因为当您将发件人转换为AnyObject
时,您将收到immutable
类型对象,因此无法更新其属性,解决问题的最佳方法是更改发件人声明从Any
到实际UIControl
表示如果是按钮,则为UIButton
。
@IBAction func onFilter(_ sender: UIButton) {
hideSecondaryMenu()
sender.isSelected = !sender.isSelected
}
如果您仍想使用Any
,请将发件人转换为其所属的实际UIControl
。
@IBAction func onFilter(_ sender: Any) {
if sender is UIButton {
let btn = sender as! UIButton
hideSecondaryMenu()
btn.isSelected = !btn.isSelected
}
}