Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chhoda

macrumors 6502
Original poster
Oct 25, 2008
285
1
Hi All,

I am trying to do a customised UITableview by drawing different images...
I could not really understand view controller based implementations, so i thought i would write mine. in fact i find it easier to write without using nib files

i wrote following code

unfortunately code never comes to cellForRowAtIndexPath:(NSIndexPath nor to drawrect of cellview ...

what am i doing wrong ?
////////////////////////////////////////

____________________________
inherited from TableViewCell
_____________________________

#import "CustomTableCell.h"

@implementation CustomTableCell
{
@synthesize image;

- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
// Initialization code
}

return self;
}

- (void)drawRect:(CGRect)rect
{
// Drawing code
[self.image drawAtPoint:CGPointMake(0,0)];

}

- (void)dealloc
{
[super dealloc];
}

@end
___________________________________
inherited from UITableView and implements <UITableViewDelegate>
___________________________________


#import "CustomTableCell.h"
@implementation CustomTableView
- (UIImage*)getImage:(NSString *)imgUrl
{
id path = imgUrl;
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
return img;
}
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
cellViews = [[NSMutableArray alloc] init];
//CGRect rect = CGRectMake(0, 0, 50, 50);
CustomTableCell *eventsView = [[CustomTableCell alloc] initWithFrame:frame];
eventsView.image = [self getImage:mad:"pic1.png"];
[cellViews addObject:eventsView];
[eventsView release];

CustomTableCell *newsView = [[CustomTableCell alloc] initWithFrame:frame];
newsView.image = [self getImage:mad:"pic2.png"];
[cellViews addObject:newsView];
[newsView release];
}
return self;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"row #");
return [cellViews objectAtIndex:0];
}

- (void)dealloc {
[super dealloc];
}
@end


///////////////////////////////////////
 

chhoda

macrumors 6502
Original poster
Oct 25, 2008
285
1
Thanks

Hi jnic,

Thanks, it worked. Now I have a couple of questions more..

I want to put checkbox - text - image - text in each row. How would i do that ? can i create 4 columns ?

also i tried returning more than 1 in
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

but i did not see any difference ... what does this do ? and how does it look like with multiple sections ?

more so i want only check box being clickable instead of the whole row.
how can i fade the rectangle that selects the row ?

ch
 

chhoda

macrumors 6502
Original poster
Oct 25, 2008
285
1
re: thanks

I figured out UITableViewCellAccessoryCheckmark did the trick for me. Still the question remains, can i mark indicator only a portion of the cell ?

regards
ch
 

jagatnibas

macrumors regular
Jul 28, 2008
126
0
going nuts over uitableview

oh me god... i am scratching my head outa nothing over uitableview...

I have written the following code. but when the table view is drawn, the images are coming overlapped. I dont know what is wrong with this. I have hardcoed the cell frame and changing them does not affect the cell appearance at all and middle cell overlaps a bit to top and buttom to middle.

please give me some ideas, i am on a very strict deadline

//////////////////////////////////////////////////////////////////

- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
[self setDelegate:self];
[self setDataSource:self];

cellViews = [[NSMutableArray alloc] init];

CGRect rect = CGRectMake(0, 0, 70, 170);

UITableViewCell *oneView = [[UITableViewCell alloc] initWithFrame:rect];
[oneView setImage:[self getImage:mad:"1.png"]];
[cellViews addObject:eek:neView];
[oneView release];

UITableViewCell *twoView = [[UITableViewCell alloc] initWithFrame:rect];
[twoView setImage:[self getImage:mad:"2.png"]];
[cellViews addObject:twoView];
[twoView release];

UITableViewCell *threeView = [[UITableViewCell alloc] initWithFrame:rect];
[threeView setImage:[self getImage:mad:"3.png"]];
[cellViews addObject:threeView];
[threeView release];
}

return self;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//NSLog(@"row #%d, %d", indexPath.row, indexPath.section);
return [cellViews objectAtIndex:indexPath.row];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//NSLog(@"Section %d", section);
return [cellViews count];
}

//////////////////////////////////////////////////////////////////
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.