-1

Where is the problem? I want to make a Table View and if u click on the cell it pops up another Table View What i must to do to fix that?

    - (UITableViewCell )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier2 = @"TableViewCell_2"; 
    TableViewController_2 *cell2 = (TableViewController_2)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier2 forIndexPath:indexPath]; 
    // Configure the cell... 
    int row = [indexPath row]; cell2.Spoj = _Spoj[row]; 
    return cell2; 
}
4GetFullOf
  • 1,738
  • 4
  • 22
  • 47
patrikbelis
  • 1,350
  • 2
  • 16
  • 35
  • 4
    It looks like you haven't set the identifier for your cell (or you're not using the same one in your code and in IB). – rdelmar Apr 11 '14 at 23:18
  • - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier2 = @"TableViewCell_2"; TableViewController_2 *cell2 = (TableViewController_2*)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier2 forIndexPath:indexPath]; // Configure the cell... int row = [indexPath row]; cell2.Spoj = _Spoj[row]; return cell2; } – patrikbelis Apr 11 '14 at 23:21
  • Where did you make the cell? In IB (xib or storyboard)? – rdelmar Apr 11 '14 at 23:22
  • 1
    please, edit your post instead of write the comment. it's difficult to understand – Mike Apr 11 '14 at 23:24
  • Possible duplicate of [http://stackoverflow.com/q/19989266/3476191](http://stackoverflow.com/q/19989266/3476191) – NobodyNada Apr 11 '14 at 23:24
  • Your screen shot shows that you didn't give the cell an identifier in IB. – rdelmar Apr 11 '14 at 23:30
  • 1
    Set the identifier for your prototype cell in the storyboard, and that will fix your problem at least the one problem that causes the error you posted). – rdelmar Apr 11 '14 at 23:46

2 Answers2

1

In your tableView:cellForRowAtIndexPath: use dequeueReusableCellWithIdentifier: instead of dequeueReusableCellWithIdentifier:forIndexPath:.

NobodyNada
  • 7,529
  • 6
  • 44
  • 51
  • 3
    This is wrong. Either method should work if the OP has the correct identifier. – rdelmar Apr 11 '14 at 23:21
  • The documentation is incomplete, and partially wrong. If you make the cell in the storyboard, you can use either method without registering anything. I've done it many times. – rdelmar Apr 11 '14 at 23:24
  • i need to know how to fix this warning:( – patrikbelis Apr 11 '14 at 23:44
  • Change `TableViewController_2 *cell2 = (TableViewController_2 *)[…` to `TableViewCell_2 *cell2 = (TableViewCell_2 *)[…`. – NobodyNada Apr 11 '14 at 23:46
  • http://screenshot.cz/ZPWUN/Snimka-obrazovky-2014-04-12-o1.47.41.png even worse :D – patrikbelis Apr 11 '14 at 23:48
  • At the top of your file, `#import "TableViewCell_2.h"` – NobodyNada Apr 11 '14 at 23:49
  • Sorry, I always forget about the case where you don't have a prototype cell (since I never do it that way) -- so you're right that dequeueReusableCellWithIdentifier: will work while the longer method doesn't in that situation unless you do the registration. – rdelmar Apr 12 '14 at 00:45
  • Yeah, I always forget about when you do because I am slow to upgrade to newer technologies. – NobodyNada Apr 12 '14 at 00:48
0

For correct dequeueing there are these steps:

  • On the attributes inspector for the xib file, add the identifier. (not in the restorationID field)

  • In your viewDidLoad of the ViewController owning the tableview, register the nib

    [[self.tableview registerNib:[UINib nibWithName@"TheNibName" bundle:nil] withIdentifier:@"theSameIdentierInXib"];

  • call dequeue... in cellForRow (no need to cast cell type or check for nil from iOS 5+)

*note, registerClass can cause an assertion failure if used for cell xib.

some_id
  • 29,466
  • 62
  • 182
  • 304