UIImageView inside UITableViewCell is laid out incorrectly in edit mode
I have a fairly simple UITableViewCell
:
Nothing extraordinary, but I ran into an issue. Whenever I enable the edit mode, the position and size of UIImageView
change, completely ignoring the constraints that pin it to the edges of its superview (the one with blue background):
The superview is laid out correctly:
I expected to see messages about broken constraints in the system log, but there is nothing of the sort.
Why does this happen and how do I fix it?
Here's a project that reproduces the issue: https://www.icloud.com/iclouddrive/0NvLeUettZub5uQIXUM4p0bGw#TestApp
EDIT: I tried calling layoutIfNeeded()
on the image container when the edit mode is activated:
class NoteTableViewCell: UITableViewCell
override func setEditing(_ editing: Bool, animated: Bool)
super.setEditing(editing, animated: animated)
noteImageView.superview?.layoutIfNeeded()
now the layout is incorrect even if I don't enable the edit mode.
EDIT 2: @Desdenova suggested that this might be caused by the horizontal UIStackView
, but replacing it with equivalent constraints did not fix the problem.
ios uitableview uikit
|
show 5 more comments
I have a fairly simple UITableViewCell
:
Nothing extraordinary, but I ran into an issue. Whenever I enable the edit mode, the position and size of UIImageView
change, completely ignoring the constraints that pin it to the edges of its superview (the one with blue background):
The superview is laid out correctly:
I expected to see messages about broken constraints in the system log, but there is nothing of the sort.
Why does this happen and how do I fix it?
Here's a project that reproduces the issue: https://www.icloud.com/iclouddrive/0NvLeUettZub5uQIXUM4p0bGw#TestApp
EDIT: I tried calling layoutIfNeeded()
on the image container when the edit mode is activated:
class NoteTableViewCell: UITableViewCell
override func setEditing(_ editing: Bool, animated: Bool)
super.setEditing(editing, animated: animated)
noteImageView.superview?.layoutIfNeeded()
now the layout is incorrect even if I don't enable the edit mode.
EDIT 2: @Desdenova suggested that this might be caused by the horizontal UIStackView
, but replacing it with equivalent constraints did not fix the problem.
ios uitableview uikit
Nicely asked question. Nice and clear :) Looking at project now. Did you try: setNeedsLayout on the view?
– Woodstock
Nov 15 '18 at 13:51
@Woodstock thank you :) Which view do you mean? The image container?
– Andrii Chernenko
Nov 15 '18 at 14:00
I would have thought the UITableViewCell’s View
– Woodstock
Nov 15 '18 at 14:02
Also try calling self.view.layoutIfNeeded() where self is the tableviewCell. (After invoking the edit of course)
– Woodstock
Nov 15 '18 at 14:05
@Woodstock Obviously edit mode lays out the sub views. My best guess would be horizontal stack view is misbehaving. And I don't think he even needs that stack view.
– Desdenova
Nov 15 '18 at 14:13
|
show 5 more comments
I have a fairly simple UITableViewCell
:
Nothing extraordinary, but I ran into an issue. Whenever I enable the edit mode, the position and size of UIImageView
change, completely ignoring the constraints that pin it to the edges of its superview (the one with blue background):
The superview is laid out correctly:
I expected to see messages about broken constraints in the system log, but there is nothing of the sort.
Why does this happen and how do I fix it?
Here's a project that reproduces the issue: https://www.icloud.com/iclouddrive/0NvLeUettZub5uQIXUM4p0bGw#TestApp
EDIT: I tried calling layoutIfNeeded()
on the image container when the edit mode is activated:
class NoteTableViewCell: UITableViewCell
override func setEditing(_ editing: Bool, animated: Bool)
super.setEditing(editing, animated: animated)
noteImageView.superview?.layoutIfNeeded()
now the layout is incorrect even if I don't enable the edit mode.
EDIT 2: @Desdenova suggested that this might be caused by the horizontal UIStackView
, but replacing it with equivalent constraints did not fix the problem.
ios uitableview uikit
I have a fairly simple UITableViewCell
:
Nothing extraordinary, but I ran into an issue. Whenever I enable the edit mode, the position and size of UIImageView
change, completely ignoring the constraints that pin it to the edges of its superview (the one with blue background):
The superview is laid out correctly:
I expected to see messages about broken constraints in the system log, but there is nothing of the sort.
Why does this happen and how do I fix it?
Here's a project that reproduces the issue: https://www.icloud.com/iclouddrive/0NvLeUettZub5uQIXUM4p0bGw#TestApp
EDIT: I tried calling layoutIfNeeded()
on the image container when the edit mode is activated:
class NoteTableViewCell: UITableViewCell
override func setEditing(_ editing: Bool, animated: Bool)
super.setEditing(editing, animated: animated)
noteImageView.superview?.layoutIfNeeded()
now the layout is incorrect even if I don't enable the edit mode.
EDIT 2: @Desdenova suggested that this might be caused by the horizontal UIStackView
, but replacing it with equivalent constraints did not fix the problem.
ios uitableview uikit
ios uitableview uikit
edited Jan 10 at 7:25
Andrii Chernenko
asked Nov 15 '18 at 13:46
Andrii ChernenkoAndrii Chernenko
6,32055470
6,32055470
Nicely asked question. Nice and clear :) Looking at project now. Did you try: setNeedsLayout on the view?
– Woodstock
Nov 15 '18 at 13:51
@Woodstock thank you :) Which view do you mean? The image container?
– Andrii Chernenko
Nov 15 '18 at 14:00
I would have thought the UITableViewCell’s View
– Woodstock
Nov 15 '18 at 14:02
Also try calling self.view.layoutIfNeeded() where self is the tableviewCell. (After invoking the edit of course)
– Woodstock
Nov 15 '18 at 14:05
@Woodstock Obviously edit mode lays out the sub views. My best guess would be horizontal stack view is misbehaving. And I don't think he even needs that stack view.
– Desdenova
Nov 15 '18 at 14:13
|
show 5 more comments
Nicely asked question. Nice and clear :) Looking at project now. Did you try: setNeedsLayout on the view?
– Woodstock
Nov 15 '18 at 13:51
@Woodstock thank you :) Which view do you mean? The image container?
– Andrii Chernenko
Nov 15 '18 at 14:00
I would have thought the UITableViewCell’s View
– Woodstock
Nov 15 '18 at 14:02
Also try calling self.view.layoutIfNeeded() where self is the tableviewCell. (After invoking the edit of course)
– Woodstock
Nov 15 '18 at 14:05
@Woodstock Obviously edit mode lays out the sub views. My best guess would be horizontal stack view is misbehaving. And I don't think he even needs that stack view.
– Desdenova
Nov 15 '18 at 14:13
Nicely asked question. Nice and clear :) Looking at project now. Did you try: setNeedsLayout on the view?
– Woodstock
Nov 15 '18 at 13:51
Nicely asked question. Nice and clear :) Looking at project now. Did you try: setNeedsLayout on the view?
– Woodstock
Nov 15 '18 at 13:51
@Woodstock thank you :) Which view do you mean? The image container?
– Andrii Chernenko
Nov 15 '18 at 14:00
@Woodstock thank you :) Which view do you mean? The image container?
– Andrii Chernenko
Nov 15 '18 at 14:00
I would have thought the UITableViewCell’s View
– Woodstock
Nov 15 '18 at 14:02
I would have thought the UITableViewCell’s View
– Woodstock
Nov 15 '18 at 14:02
Also try calling self.view.layoutIfNeeded() where self is the tableviewCell. (After invoking the edit of course)
– Woodstock
Nov 15 '18 at 14:05
Also try calling self.view.layoutIfNeeded() where self is the tableviewCell. (After invoking the edit of course)
– Woodstock
Nov 15 '18 at 14:05
@Woodstock Obviously edit mode lays out the sub views. My best guess would be horizontal stack view is misbehaving. And I don't think he even needs that stack view.
– Desdenova
Nov 15 '18 at 14:13
@Woodstock Obviously edit mode lays out the sub views. My best guess would be horizontal stack view is misbehaving. And I don't think he even needs that stack view.
– Desdenova
Nov 15 '18 at 14:13
|
show 5 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320870%2fuiimageview-inside-uitableviewcell-is-laid-out-incorrectly-in-edit-mode%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320870%2fuiimageview-inside-uitableviewcell-is-laid-out-incorrectly-in-edit-mode%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Nicely asked question. Nice and clear :) Looking at project now. Did you try: setNeedsLayout on the view?
– Woodstock
Nov 15 '18 at 13:51
@Woodstock thank you :) Which view do you mean? The image container?
– Andrii Chernenko
Nov 15 '18 at 14:00
I would have thought the UITableViewCell’s View
– Woodstock
Nov 15 '18 at 14:02
Also try calling self.view.layoutIfNeeded() where self is the tableviewCell. (After invoking the edit of course)
– Woodstock
Nov 15 '18 at 14:05
@Woodstock Obviously edit mode lays out the sub views. My best guess would be horizontal stack view is misbehaving. And I don't think he even needs that stack view.
– Desdenova
Nov 15 '18 at 14:13