AttributedString on a CollectionView cell is not displaying string value










-1















I have a UICollectinViewCell with a label set to attributedString.



Inside cellForItem, I cast a simple string to an NSAttributedString so that I can set the UILabel's attributedText property.



The string "Attributed String Text" only appears if I scroll the CollectionView. If I do not scroll, "Label" appears, as that's the text that is set in IB. If I keep the UILabel as plain, the correct text appears just fine.



// cellForItemAt
let string = "Attributed String Text"
let mutableAttributedString = NSAttributedString(string: string)
cell.subName.attributedText = mutableAttributedString


How can I get the attributedText to show without having to scroll the CollectionView?










share|improve this question






















  • Where you set the delegate and dataSource ?

    – Sh_Khan
    Nov 13 '18 at 19:45











  • I set the delegate and dataSource in viewDidLoad.

    – Joe
    Nov 13 '18 at 22:01











  • can you post full context

    – Sh_Khan
    Nov 13 '18 at 22:06











  • Try cell.subName.text = "Something" instead. If you don't see something, that's not related to NSAttributedString, but UICollectionView. But we need more context, full code of cellForItemAt, a reuse issue?

    – Larme
    Nov 14 '18 at 6:51











  • @Larme Thanks, I will try that. I will post more code from the project as well.

    – Joe
    Nov 14 '18 at 15:11















-1















I have a UICollectinViewCell with a label set to attributedString.



Inside cellForItem, I cast a simple string to an NSAttributedString so that I can set the UILabel's attributedText property.



The string "Attributed String Text" only appears if I scroll the CollectionView. If I do not scroll, "Label" appears, as that's the text that is set in IB. If I keep the UILabel as plain, the correct text appears just fine.



// cellForItemAt
let string = "Attributed String Text"
let mutableAttributedString = NSAttributedString(string: string)
cell.subName.attributedText = mutableAttributedString


How can I get the attributedText to show without having to scroll the CollectionView?










share|improve this question






















  • Where you set the delegate and dataSource ?

    – Sh_Khan
    Nov 13 '18 at 19:45











  • I set the delegate and dataSource in viewDidLoad.

    – Joe
    Nov 13 '18 at 22:01











  • can you post full context

    – Sh_Khan
    Nov 13 '18 at 22:06











  • Try cell.subName.text = "Something" instead. If you don't see something, that's not related to NSAttributedString, but UICollectionView. But we need more context, full code of cellForItemAt, a reuse issue?

    – Larme
    Nov 14 '18 at 6:51











  • @Larme Thanks, I will try that. I will post more code from the project as well.

    – Joe
    Nov 14 '18 at 15:11













-1












-1








-1


1






I have a UICollectinViewCell with a label set to attributedString.



Inside cellForItem, I cast a simple string to an NSAttributedString so that I can set the UILabel's attributedText property.



The string "Attributed String Text" only appears if I scroll the CollectionView. If I do not scroll, "Label" appears, as that's the text that is set in IB. If I keep the UILabel as plain, the correct text appears just fine.



// cellForItemAt
let string = "Attributed String Text"
let mutableAttributedString = NSAttributedString(string: string)
cell.subName.attributedText = mutableAttributedString


How can I get the attributedText to show without having to scroll the CollectionView?










share|improve this question














I have a UICollectinViewCell with a label set to attributedString.



Inside cellForItem, I cast a simple string to an NSAttributedString so that I can set the UILabel's attributedText property.



The string "Attributed String Text" only appears if I scroll the CollectionView. If I do not scroll, "Label" appears, as that's the text that is set in IB. If I keep the UILabel as plain, the correct text appears just fine.



// cellForItemAt
let string = "Attributed String Text"
let mutableAttributedString = NSAttributedString(string: string)
cell.subName.attributedText = mutableAttributedString


How can I get the attributedText to show without having to scroll the CollectionView?







swift string uicollectionview uilabel nsattributedstring






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 19:44









JoeJoe

1,14211432




1,14211432












  • Where you set the delegate and dataSource ?

    – Sh_Khan
    Nov 13 '18 at 19:45











  • I set the delegate and dataSource in viewDidLoad.

    – Joe
    Nov 13 '18 at 22:01











  • can you post full context

    – Sh_Khan
    Nov 13 '18 at 22:06











  • Try cell.subName.text = "Something" instead. If you don't see something, that's not related to NSAttributedString, but UICollectionView. But we need more context, full code of cellForItemAt, a reuse issue?

    – Larme
    Nov 14 '18 at 6:51











  • @Larme Thanks, I will try that. I will post more code from the project as well.

    – Joe
    Nov 14 '18 at 15:11

















  • Where you set the delegate and dataSource ?

    – Sh_Khan
    Nov 13 '18 at 19:45











  • I set the delegate and dataSource in viewDidLoad.

    – Joe
    Nov 13 '18 at 22:01











  • can you post full context

    – Sh_Khan
    Nov 13 '18 at 22:06











  • Try cell.subName.text = "Something" instead. If you don't see something, that's not related to NSAttributedString, but UICollectionView. But we need more context, full code of cellForItemAt, a reuse issue?

    – Larme
    Nov 14 '18 at 6:51











  • @Larme Thanks, I will try that. I will post more code from the project as well.

    – Joe
    Nov 14 '18 at 15:11
















Where you set the delegate and dataSource ?

– Sh_Khan
Nov 13 '18 at 19:45





Where you set the delegate and dataSource ?

– Sh_Khan
Nov 13 '18 at 19:45













I set the delegate and dataSource in viewDidLoad.

– Joe
Nov 13 '18 at 22:01





I set the delegate and dataSource in viewDidLoad.

– Joe
Nov 13 '18 at 22:01













can you post full context

– Sh_Khan
Nov 13 '18 at 22:06





can you post full context

– Sh_Khan
Nov 13 '18 at 22:06













Try cell.subName.text = "Something" instead. If you don't see something, that's not related to NSAttributedString, but UICollectionView. But we need more context, full code of cellForItemAt, a reuse issue?

– Larme
Nov 14 '18 at 6:51





Try cell.subName.text = "Something" instead. If you don't see something, that's not related to NSAttributedString, but UICollectionView. But we need more context, full code of cellForItemAt, a reuse issue?

– Larme
Nov 14 '18 at 6:51













@Larme Thanks, I will try that. I will post more code from the project as well.

– Joe
Nov 14 '18 at 15:11





@Larme Thanks, I will try that. I will post more code from the project as well.

– Joe
Nov 14 '18 at 15:11












1 Answer
1






active

oldest

votes


















0














I figured it out. I believe it may be an Xcode bug. Nothing was wrong with my code. Normal (plain) text UILabel was displaying proper text just fine. When I switched it to attributed UILabel, the text stopped displaying with no other code changes.



After digging around for a while, I found this thread: Label text in UICollectionViewCell not updating where user Jacksonsox was having a similar issue.



In Interface Builder, I removed the connection to the UILabel that wasn't updating, deleted the UILabel, re-added a new label, re-connected it, set it to Attributed text, and the text now shows up just fine. Again, no code changes made. Only changes were in IB.



I hope this helps others who are experiencing similar issues.






share|improve this answer






















    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
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288402%2fattributedstring-on-a-collectionview-cell-is-not-displaying-string-value%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I figured it out. I believe it may be an Xcode bug. Nothing was wrong with my code. Normal (plain) text UILabel was displaying proper text just fine. When I switched it to attributed UILabel, the text stopped displaying with no other code changes.



    After digging around for a while, I found this thread: Label text in UICollectionViewCell not updating where user Jacksonsox was having a similar issue.



    In Interface Builder, I removed the connection to the UILabel that wasn't updating, deleted the UILabel, re-added a new label, re-connected it, set it to Attributed text, and the text now shows up just fine. Again, no code changes made. Only changes were in IB.



    I hope this helps others who are experiencing similar issues.






    share|improve this answer



























      0














      I figured it out. I believe it may be an Xcode bug. Nothing was wrong with my code. Normal (plain) text UILabel was displaying proper text just fine. When I switched it to attributed UILabel, the text stopped displaying with no other code changes.



      After digging around for a while, I found this thread: Label text in UICollectionViewCell not updating where user Jacksonsox was having a similar issue.



      In Interface Builder, I removed the connection to the UILabel that wasn't updating, deleted the UILabel, re-added a new label, re-connected it, set it to Attributed text, and the text now shows up just fine. Again, no code changes made. Only changes were in IB.



      I hope this helps others who are experiencing similar issues.






      share|improve this answer

























        0












        0








        0







        I figured it out. I believe it may be an Xcode bug. Nothing was wrong with my code. Normal (plain) text UILabel was displaying proper text just fine. When I switched it to attributed UILabel, the text stopped displaying with no other code changes.



        After digging around for a while, I found this thread: Label text in UICollectionViewCell not updating where user Jacksonsox was having a similar issue.



        In Interface Builder, I removed the connection to the UILabel that wasn't updating, deleted the UILabel, re-added a new label, re-connected it, set it to Attributed text, and the text now shows up just fine. Again, no code changes made. Only changes were in IB.



        I hope this helps others who are experiencing similar issues.






        share|improve this answer













        I figured it out. I believe it may be an Xcode bug. Nothing was wrong with my code. Normal (plain) text UILabel was displaying proper text just fine. When I switched it to attributed UILabel, the text stopped displaying with no other code changes.



        After digging around for a while, I found this thread: Label text in UICollectionViewCell not updating where user Jacksonsox was having a similar issue.



        In Interface Builder, I removed the connection to the UILabel that wasn't updating, deleted the UILabel, re-added a new label, re-connected it, set it to Attributed text, and the text now shows up just fine. Again, no code changes made. Only changes were in IB.



        I hope this helps others who are experiencing similar issues.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 18:31









        JoeJoe

        1,14211432




        1,14211432





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288402%2fattributedstring-on-a-collectionview-cell-is-not-displaying-string-value%23new-answer', 'question_page');

            );

            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







            Popular posts from this blog

            How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

            Syphilis

            Darth Vader #20