简体   繁体   English

UIbutton imageview在tableview的每个单元格中都不相同

[英]UIbutton imageview is not same in every cell of tableview

could anyone help me Im pretty desperate with my tableview. 谁能帮助我,我对我的tableview感到绝望。 Basically I have this tableview with button as checkbox 基本上我有这个带有按钮作为复选框的tableview

this is how I suppy my data to button 这就是我向按钮提供数据的方式

BOOL isChecked = [model.isChecked boolValue];
    self.checkBoxButton.selected = isChecked;
    self.checkBoxButton.contentHorizontalAlignment = UIControlContentVerticalAlignmentFill;
    self.checkBoxButton.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
    self.checkBoxButton.imageView.contentMode = UIViewContentModeScaleAspectFit;

this is my tableview looks like 这是我的tableview看起来像

I would like my uibutton image be same size as the big ones. 我希望uibutton图像的大小与大图像的大小相同。

when my view loads the sizes of images is fine..however when i begin the touch of button the images begin to collapse, it even put the big ones smaller and smaller ones bigger randomly. 当我的视图加载图像时,图像的大小就可以了。但是,当我开始触摸按钮时,图像开始崩溃,它甚至随机将大图像和小图像随机放大。

Per update 每次更新

Looks to me like the button isn't set to UIButtonTypeCustom and the system is somehow adjusting it on the touch began event. 在我看来,该按钮未设置为UIButtonTypeCustom ,并且系统在触摸开始事件上以某种方式对其进行了调整。 Try changing the button type to custom. 尝试将按钮类型更改为自定义。


In the cellForRowAtIndexPath delegate method, after you dequeue a reusable cell, try resetting the checkbox to either nil or its default image, or try forcing its BOOL value to false. cellForRowAtIndexPath委托方法中, 使可重复使用的单元格出队之后 ,尝试将复选框重置为nil或其默认图像,或者尝试将其BOOL值强制设置为false。 Once you've reset the image, then try calling the method (not setting the property) for selected: 重置图像后,请尝试为所选对象调用方法(未设置属性):

BOOL isChecked = [model.isChecked boolValue];
[self.checkBoxButton setSelected:isChecked];

My vague guess to what's going on here is that somehow the value from the model is being retrieved before the cell is dequeued, and thus it retains some value from the last time the cell was used. 我对这里发生的事情的含糊猜测是,在某种程度上,该模型的值是在单元出队之前被检索的,因此它保留了自上次使用该单元以来的某些值。 If you clear it out after dequeuing, then set the value from the model, it should set it correctly. 如果您在出队后将其清除,然后从模型中设置值,则它应该正确设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM