This is my code for the UITableViews:

```
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == _tblConnectedDevices){
        return [_arrConnectedDevices count];
    }
    if ([filePathsArray count] > 0){
        return [filePathsArray count];
    }
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == _tblConnectedDevices){
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellIdentifier"];
    }

    cell.textLabel.text = [_arrConnectedDevices objectAtIndex:indexPath.row];

    return cell;
    } else {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory  error:nil];
        NSString *last = [documentsDirectory stringByAppendingPathComponent:[filePathsArray objectAtIndex:indexPath.row]];
        NSString *last2 = [[last lastPathComponent] stringByDeletingPathExtension];
        cell.textLabel.text = last2;
        return cell;
    }

}

```

At first launch, with the app not installed on the device, the application will crash with this error: 

```
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'

```

If I amend `-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{` to include: 

```
    if ([filePathsArray count] == 0){
    return [filePathsArray count];
}

```

(I add the == 0 as well as > )
Then the app launches fine, but without displaying my UITableView correctly.
If I then close the app, and remove the added code, and launch it again, it works perfectly as expected.
What am I doing wrong/missing?
Thanks