Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView Content "Static cell" not working in iOS7

I have a problem in my storyboard.It is working fine but when i try to change the content property of UITableView it caused following error

Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit/UIKit-2903.23/UITableView.m Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

I want to design a grouped tableview with 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; 
} 
like image 472
Adnan Chaudhry Avatar asked Nov 04 '13 07:11

Adnan Chaudhry


2 Answers

if you use static cell, just comment all the UITableViewDatasourceDelegate method. so comment 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 this will help you!

like image 100
pingguoilove Avatar answered Oct 27 '22 01:10

pingguoilove


Instead of using:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

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

Use:

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

//-> Since you chose Static TableCells you don't need to reuse instead use the cells you created in nib

like image 39
Panfilo Mariano Avatar answered Oct 27 '22 01:10

Panfilo Mariano