Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't get contents of file from a .plist file into an array
    primarykey
    data
    text
    <p>I'm trying to create a create a simple app where I have a TableView that should display the contents of a file. I have created a Table View in IB and dragged it's delegate and data source to the file's owner and I have manually created a .plist file with 1 array that have 2 items.</p> <p>In my TableViewController.h i have declared an array. </p> <pre><code>NSArray * posts; </code></pre> <p>In my implementation file I have declared the required methods for UITableViewDataSource like this:</p> <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSLog(@"Returning num sections"); return posts.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // create a cell UITableViewCell * post = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"post"]; // fill it with content post.textLabel.text = [posts objectAtIndex:indexPath.row]; // return it return post; } </code></pre> <p>And in my ViewController 'viewDidLoad' method I try to add the content of my file to the 'posts' array like this:</p> <pre><code>- (void)viewDidLoad { NSString * postFile = [[NSBundle mainBundle] pathForResource:@"Posts" ofType:@"plist"]; posts = [[NSArray alloc] initWithContentsOfFile:postFile]; NSLog(@"%@", postFile); NSLog(@"%i", posts.count); [super viewDidLoad]; // Do any additional setup after loading the view from its nib. } </code></pre> <p>NSLog(@"%i", posts.count); returns 0, despite that I have added values to my .plist file. And nothing is displayed in the table view. </p> <p>Suggestions on how so solve this would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload