Strange behaviour on table view with core data

前端 未结 2 1250
时光说笑
时光说笑 2021-01-28 17:00

step by step I am advancing creating my first iOS app. Now I am experiencing a strange behaviour on a table view controller which I am not able to solve and I have been searchin

相关标签:
2条回答
  • 2021-01-28 17:17

    The first issue with code I noticed is you must add you code after

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    

    not before it. It will guarantee that your view is, at least, loaded.

    Second, make from all your string literals const string like this and use it everywhere

    static NSString * const kUrgentState = @"Urgent";
    

    And one more common hint: add NSLog(...); or test the value of variable in debug to localise the problem, cause right now it's really to much code, but not still not enough to find a problem. Find the moment when values of variable goes wrong and then fix your question

    0 讨论(0)
  • 2021-01-28 17:19

    Your problem appears to be in the configureCell: method. You are not taking cell reuse into account. The cell you are configuring could have need used before and could have had an urgent status previously.

    Your code only deals with the situation where the cell is urgent, in which case it adds a subview. There are two problems with this approach:

    1. A reused cell will have the subview added every time - so there could be many urgent views on top of each other. The cell should only ever add this once and keep it in a property
    2. Code must be added to configure the cell when it is not urgent (usually, an else after the if). This would hide the urgent icon.
    0 讨论(0)
提交回复
热议问题