Reputation:
I have a custom UIView
, which has a few different views, AND a UITableview
.
I have created a custom class which is a subclass of UITableViewController
. this will control the UITableview
and the Prototype cell for the UITableView
.
If i set the delegate and datasource to the parent view, I get the following error:
-[RoadSafetyAppViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x10c92f190
where RoadSafetyAppView Controller is the parent view. However, if i don't set a delegate and data source at all, my table doesn't load the images i have declared in my custom class, which is given below:
@implementation MenuController
@synthesize menuArray;
-(void) viewDidLoad
{
[super viewDidLoad];
self.menuArray = [NSMutableArray arrayWithCapacity:4];
[menuArray addObject:[UIImage imageNamed:@"Dob in a Hoon menu.png"]];
[menuArray addObject:[UIImage imageNamed:@"Report a Hazard menu.png"]];
[menuArray addObject:[UIImage imageNamed:@"Old Logo menu.png"]];
[menuArray addObject:[UIImage imageNamed:@"Council Website menu.png"]];
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.menuArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";
MenuCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.menuImage.image =[UIImage imageNamed:@"Dob in a Hoon menu.png"];
switch (indexPath.row) {
case 0:
cell.menuImage.image =[UIImage imageNamed:@"Dob in a Hoon menu.png"];
break;
case 1:
cell.menuImage.image =[UIImage imageNamed:@"Report a Hazard menu.png"];
break;
case 2:
cell.menuImage.image =[UIImage imageNamed:@"Old Logo menu.png"];
break;
case 3:
cell.menuImage.image =[UIImage imageNamed:@"Council Website menu.png"];
break;
default:
break;
}
return cell;
}
Can someone either point out where i am going wrong with my images, or what i need to set my delegate/data source to?
Thanks.
Upvotes: 2
Views: 2544
Reputation: 964
Set delegate and datasouce by coding in viewDidLoad method of MenuController
_tblView.delegate = self;
_tblView.dataSource = self;
Upvotes: 1
Reputation: 5369
At your MenuController.h
MenuController : UIViewController<UITableViewDelegate,UITableViewDataSource>
And connect UITableView with Delegate&Datasource at Interface Builder..
Hope it fixes your issue..!
Upvotes: 1