I have a dynamic table view in a view controller that is set as both the table view's delegate and data source. I made sure to declare the subclass as a table view delegate and a table view data source. The table view is connected to the view controller's code via an outlet.
Here is the subclass's implementation code. To keep my app's code a secret, I have replaced some pieces of code with
.
EDIT: I got the error because in my tableViewCellForRow method, I have the returned variable set to something other than a table view cell. Doh!
Here is the subclass's implementation code. To keep my app's code a secret, I have replaced some pieces of code with
Code:
// removed
Code:
NSArray *managedObjects;
NSArray *attributes;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
attributes = @[// removed];
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:// removed inManagedObjectContext:[delegate managedObjectContext]];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
NSError *error;
managedObjects = [[delegate managedObjectContext] executeFetchRequest:request error:&error];
if (managedObjects == nil)
{
NSLog([error localizedDescription]);
}
[[self // removed] reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [managedObjects count];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [[managedObjects objectAtIndex:section] valueForKey:// removed];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSManagedObject *managedObject = [managedObjects objectAtIndex:indexPath.section];
return [managedObject valueForKey:[attributes objectAtIndex:indexPath.row]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
EDIT: I got the error because in my tableViewCellForRow method, I have the returned variable set to something other than a table view cell. Doh!
Last edited: