I have created .h and .m files for UITableView
called mainTableViewgm.h
and mainTableViewgm.m
resp. and I am calling -initWithFrame
: method from my main view controller to this mainTableViewgm.m
implementation file
[[mainTableViewgm alloc]initWithFrame:tableViewOne.frame]
Note that this tableview is in my main view controller. But I have created separate files for the tableView and have also set the custom class to mainTableViewgm
in storyboard.
the -initWithFrame:
methods appears as follows
- (id)initWithFrame:(CGRect)frame
{
//NSLog(@"kource data");
self = [super initWithFrame:frame];
if (self)
{
[self setDelegate:self];
[self setDataSource:self];
[self tableView:self cellForRowAtIndexPath:0];
[self tableView:self numberOfRowsInSection:1];
// Initialization code
}
return self;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"kource data");
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"kource data2");
UITableViewCell*cellOne =[[UITableViewCell alloc]init];
cellOne.detailTextLabel.text=@"text did appear";
return cellOne;
}
the -initWithFrame:
is being called fine along with the 'if (self)' block in this method. But the problem is numberOfRowsInSection:
and cellForRowAtIndexPath:
are not being automatically called here . kource data
/kource data2
never appear in log. What do I do to load the table? Are the delegate
/datasource
being set incorrectly?
I must mention that I have also set the UITableViewDelegate
and UITableviewDataSource
protocols:
@interface mainTableViewgm : UITableView <UITableViewDelegate,UITableViewDataSource>
@end
Help will be much appreciated. Thank you.