UITableView Static Cell Content Does Not Work in iOS7

I have a problem in my storyboard. It works fine, but when I try to change the content property of the UITableView, it causes the following error

Assertion error in - [UITableView dequeueReusableCellWithIdentifier: forIndexPath:], / SourceCache / UIKit / UIKit-2903.23 / UITableView.m Application terminated due to unannounced exception "NSInternalInconsistencyException", reason: "could not delete cell with Cell identifier - must register either or class for identifier or connect prototype cell in storyboard "

I want to create a grouped tableview with a static cell. thanks in advance

code

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 2; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 3; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; return cell; } 
+6
source share
7 answers

if you are using a static cell, just comment out the whole UITableViewDatasourceDelegate method. so comment on the following code:

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 2; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 3; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; return cell; } 

Wish it helps you!

+7
source

Instead of using:

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

// -> This is used when using prototype cells (e.g. Dynamic TableView

Application:

 UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath]; 

// -> Since you selected Static TableCells, you do not need to reuse the cells you created in nib

+4
source

I ran into the same problem and I think I found a way to solve this problem.

  • The creation of the controller continues from the UITableViewController to wrap its controller; it will have UITableViewDelegate and UITableViewDataSource default methods.
  • Delete UITableView delegate and data source
  • Delete the default UITableViewDelegate and UITableViewDataSource files from your controller file, since these are static cells, therefore, if they exist, they will not be displayed

Hope this helps.

+1
source

When using the storyboard, the tableview cell must be registered in the storyboard. This means that the cell must be added to the table and its identifier must be set. This identifier should be used in the code in cellForRowAtIndexpath

EDIT

In the case of static cells, each clean mesh should be created at the tip and filled with content using code or nib

Read it

0
source

You cannot use static cells in a normal UITableView.

Instead, you need to use the UITableViewController to navigate with static cells.

this and this can or can help.

0
source
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [YourArr count]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 44; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = [NSString stringWithFormat:@"cell %d",indexPath.row]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; cell = nil; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } return cell; } 
0
source

Add this code to cellForRowAtIndexPath

 static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; } else { UIView *subview; while ((subview= [[[cell contentView]subviews]lastObject])!=nil) [subview removeFromSuperview]; } 
0
source

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


All Articles