I have designed my UITableViewCell in iPhone. Unfortunately I need to redesign the Cell. I will explain my problem. My previous/current cell design like below:
Header(11.1.2012) //single row
event1
time1
Header(12.1.2012) //single row
event1
time1
Header(13.1.2012) //single row
event1
time1
Header(13.1.2012) //single row
event2
time2
Header(13.1.2012) //single row
event3
time3
Header(11.1.2012)
event1 is a singel row in a TableView cell. But, i need to change the design like this:
Header(11.1.2012) //single row
event1
time1
Header(12.1.2012) //single row
event1
time1
Header(13.1.2012) //single row
event1
time1
event2
time2
event3
time3
I’m really confused as to how to do this? Can anyone please suggest any ideas and sample code to do like this?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UIView *dateView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
dateView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"transactionHeader.png"]];
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 300, 30)];
headerLabel.tag = 100;
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.font = [UIFont fontWithName:@"Helvetica" size:16];
headerLabel.font = [UIFont boldSystemFontOfSize:16];
headerLabel.highlightedTextColor = [UIColor whiteColor];
[dateView addSubview: headerLabel];
[cell.contentView addSubview:dateView];
UILabel *eventLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 300, 25)];
eventLabel.tag = 101;
eventLabel.backgroundColor = [UIColor clearColor];
eventLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
eventLabel.font = [UIFont boldSystemFontOfSize:14];
eventLabel.highlightedTextColor = [UIColor whiteColor];
[cell.contentView addSubview: eventLabel];
UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 55, 300, 25)];
timeLabel.tag = 102;
timeLabel.backgroundColor = [UIColor clearColor];
timeLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
timeLabel.highlightedTextColor = [UIColor whiteColor];
[cell.contentView addSubview: timeLabel];
}
UILabel * headerLabel = (UILabel *) [cell.contentView viewWithTag:100];
headerLabel.text = [headerDateArray objectAtIndex:indexPath.row];
UILabel *eventLabel = (UILabel *) [cell.contentView viewWithTag:101];
eventLabel.text = [eventArray objectAtIndex:indexPath.row];
UILabel * timeLabel = (UILabel *) [cell.contentView viewWithTag:102];
timeLabel.text = [timeArray objectAtIndex:indexPath.row];
return cell;
}
Currently am using this code in my project. What i need to change? Thanks.
Hi Thanks to all for answering and viewing my question. I have got the idea and solved the problem. I have added Header for each row and removed the header where the data returns null.
Now, it is working very well in my app. Once again i thank you all.