New to Xcode; reuse identifiers?

I recently started creating a very simple to-do list in Xcode 5 as my first project. Having almost finished developing and building the user interface, I am now stuck with embedding data in my TableView. I added a list of 13 elements in my list and gave the first identifier in the list, "ListPrototypeCell", and all of my code seems to be correct. My project has 3 identical problems:

Unsupported Configuration; Prototype cells must have reuse identifiers 

I played with identifiers on each element, although I was told that I did not need to use an identifier for each element, and I still get these errors.

I am ready to send my project to anyone who thinks that they can help me solve problems, for the trained eye, this is probably a very simple mistake I made.

I appreciate any help!

+6
source share
5 answers

Try this Check your storyboard and make sure there is a reuse identifier for your Cell prototype,

enter image description here

And use the same id in

 UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"sameReuseIdentifier"]; 
+15
source

Go into your storyboard, go to the view controller, go to the table view, go to the viewview table, go to the identity inspector and enter something in the box that says "Reuse ID"

You use the reuse identifier to initialize the cells based on the style they are in the table view as follows:

 UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier"]; 
+2
source

reuseidentifier is an identifier from which you can get a cell. if you set the cell identifier again, you can access this cell in the cellForRowAtIndexPath method

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } 

which means that you will get a cell from the board using reuseid "cell". in your case you should write above two lines as follows

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; } 

this line shows that every time a new cell is assigned and initialized, and it does not use a prototype cell.

therefore, the prototype cell from the storyboard is never used. if you want, I can give you a demo to mention how this works.

+1
source

The reason you get this error is because some of your prototypes do not have a reuse identifier.

If you do not understand how / when to use prototypes and reuse identifiers. You should read: Table Programming Guide for iOS

0
source

I know this is deprecated, but I saw this explanation of reuse identifiers, and it really helped me understand why reuse identifiers are used, so I would like to share if this helps others.

"The reuse identifier is used to group similar rows in a UITableView, that is, rows that differ only in their contents, but otherwise have similar layouts.

A UITableView typically allocates enough UITableViewCell objects to display the contents visible in the table. If reuseIdentifier is set to non-nil, then when scrolling through the table view, the UITableView will first try to reuse the already allocated UITableViewCell with the same reuse identifier. If reuseIdentifier has not been set, the UITableView will be forced to allocate new UITableViewCell objects for each new element that scrolls in view, which could potentially lead to delays in the animation. "

0
source

Source: https://habr.com/ru/post/971751/


All Articles