UITableView not getting populated
Posted
by jayshree430
on Stack Overflow
See other posts from Stack Overflow
or by jayshree430
Published on 2010-04-17T06:49:28Z
Indexed on
2010/04/17
6:53 UTC
Read the original article
Hit count: 530
Hi. I have a peculiar problem. I created a normal Objective c class called SampleTable. I then extended UITableView instead of NSObject. Then in the initWithFrame constructor i initialized the table. I also made a NSMutableArray object for the datasource. I also conformed UITableViewDelegate and UITableViewDatasource. I have overridden the necessary methods also.
Now i made an object of this class in another class, and added the object as a subview. The tableView is getting drawn according to the CGRectMake() coordinates i gave to the initWithFrame constructor. But it is not getting populated with the data. I dnt know what the problem is . Can plz someone help me.
SampleTable.h
#import
@interface SampleTable : UITableView {
NSMutableArray *ItemArray;
}
@property (nonatomic,retain) NSMutableArray *ItemArray;
-(NSMutableArray *) displayItemArray;
@end
SampleTable.m
#import "SampleTable.h"
@implementation SampleTable
@synthesize ItemArray;
-(id)initWithFrame:(CGRect)frm {
[super initWithFrame:frm];
self.delegate=self;
self.dataSource=self;
[self reloadData];
return self;
}
-(NSMutableArray *) displayItemArray {
if(ItemArray==nil) {
ItemArray=[[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",nil];
}
return ItemArray;
}
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [ItemArray count];
}
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
[cell autorelease];
}
NSString *temp=[self.ItemArray objectAtIndex:indexPath.row];
cell.textLabel.text = temp;
return cell;
}
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"didselect");
}
-(void) dealloc {
[ItemArray release];
[super dealloc];
}
@end
© Stack Overflow or respective owner