0

So yesterday i began learning iOS programming, and i followed the tutorial for the to-do app.https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/SecondTutorial.html#//apple_ref/doc/uid/TP40011343-CH8-SW1

I have created my own tablelistviewcontroller as the guide tells me, and all my previous static data is gone when i boot, and the tutorial tells me this

you’ll notice that it implements three methods—numberOfSectionsInTableView:, tableView:numberOfRowsInSection:, and tableView:cellForRowAtIndexPath:. You can get your static data to display again by commenting out the implementations of these methods. Go ahead and try that out if you like.

So i commented out the cellForRowAtIndexPath, it was the only one commented out. And then i got an error at the "reuseIdentifier", so after a time of googling, i have managed to name my cells "Cells" and i ended up with this code,

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cells";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    return cell;
}

But everytime i build and start the app, i cant see my previous data, i can see it in my storyboard, but not in app.. And now i am out of ideas and since i am a newbie i believe the solution is pretty easy.

Please notify if you need any additional data.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
DreamHawk
  • 785
  • 2
  • 9
  • 20
  • What do you mean by `i cant see my previous data`? – Harikrishnan Aug 13 '14 at 07:41
  • 1
    please add this line before return cell to see something in each cell. cell.textLabel.text = @"someText" – thndrkiss Aug 13 '14 at 07:43
  • Please look at this section: Display Static Content in a Table View https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/Art/ios_simulator_static_table_view_2x.png – DreamHawk Aug 13 '14 at 07:43
  • hey tableview is for displaying data not for saving data. – Anil Prasad Aug 13 '14 at 07:44
  • hey dreamhawk it is ur storyboard or simulator ? – Anil Prasad Aug 13 '14 at 07:46
  • 1. your question is not clear about what you want to do and what problem you are facing. 2. if you are trying to use the tableview to display static data, what do you mean by `previous data`? – Harikrishnan Aug 13 '14 at 07:46
  • hey if u r beginner try to learn through www.raywenderlich.com and www.appcoda.com it is best site for IOS beginner. – Anil Prasad Aug 13 '14 at 07:49
  • Previous data, with that i mean the static data that i have inserted during the chapter "Display Static Content in a Table View", later in the tutorial i am supposed to create a Custom View Controller, and after this i can no longer see the data since before, and apple tells me that i have to uncomment "cellForRowAtIndexPath" to make it visible again, but it is not working. – DreamHawk Aug 13 '14 at 07:54
  • See my answer. I think you really misunderstood the concept of tableView. – Harikrishnan Aug 13 '14 at 08:19

1 Answers1

0

I think you really misunderstood these lines:

So why doesn’t your data show up? Table views have two ways of getting data—statically or dynamically. When a table view’s controller implements the required UITableViewDataSource methods, the table view asks its view controller for data to display, regardless of whether static data has been configured in Interface Builder. If you look at XYZToDoListTableViewController.m, you’ll notice that it implements three methods—numberOfSectionsInTableView:, tableView:numberOfRowsInSection:, and tableView:cellForRowAtIndexPath:. You can get your static data to display again by commenting out the implementations of these methods. Go ahead and try that out if you like.

The thing is when you are adding data using your app, the data is no more static. It is dynamic. UITableView doesn't store your data. It just displays it. And when you are using dynamic data, you will need a datasource which will give the tableView the data to display. You must store the data by some possible storage mechanisms in IOS. Here is a link to one such tutorial which will get you started with Core Data. Here is a good tutorial which will get you started with UITableView that will display a dynamic data.

The problem is you got the concept totally wrong.

EDIT

You might have added something like <UITableViewDataSource> in the interface file and may have added the ViewController as the datasource for the table(either using ctrl-drag in story board or tableView.datasource = self; in the code). Just remove these two and your static content will display again.

Harikrishnan
  • 7,765
  • 13
  • 62
  • 113
  • But i haven't added data through the app yet, thats the next part. I have only added data through the storyboard, to the tablecells like its explained in the tutorial. But since apple says "You can get your static data to display again by commenting out the implementations of these methods.", shouldnt i be able to retreive that data again ?? – DreamHawk Aug 13 '14 at 08:22
  • Im sorry for being a trouble here, where can i see if i might have added in the Main.storyboard or added the ViewController as datasource? All i've ctrl-drag is from the "Add"-button to the "Add to-do button" controller. – DreamHawk Aug 13 '14 at 09:26
  • found a solution here ; http://stackoverflow.com/a/9952311/889771 , we'll see how far this goes, thanks although for helping such a noob as me... :) – DreamHawk Aug 13 '14 at 09:50