I have a UITableView being populated with an NSArray. Unfortunately this array is constantly changing size and contents. So I want to create a global single copy of that array (at one point in time) and use it to populate my table.
This is what I’m doing:
.h
@interface TableViewController : UITableViewController {
// ProcessListArrayHolder *processListArrayObject;
NSArray *_myArray;
}
...
@property(nonatomic,strong) NSArray *myArray;
.m
@synthesize myArray = _myArray;
// in ViewDidLoad
_myArray = [myObject myFunctionThatReturnsAnArray]; //This function returns a different array every time because the data is constantly changing
However, when I scroll, it looks like _myArray is empty, and I get a “Bad Access” trying to get a value from it.
What is the TableView doing when I scroll?
Is there any way to make it load the entire table in one go?
Edit: To fix this, I just worked with the property, “myArray”, calling it as “self.myArray”, and ignored _myArray.
First of all you should probably be using the generated setter (that’s what it’s there for)
Where do you initialize that array in the first place?
What does your
cellForRowAtIndexPathandnumberOfRowsInSectioncode look like? If you have a properly initialized array and properly set up delegate functions, you should never receive a bad access. As you scroll, the table view is using its delegates to populate and display just the cells it needs at the time.