2009-09-08

How to add two data fields to a table row in an iPhone application

@synthesize listData;
@synthesize ticketNumbers;
@synthesize sBar;
@synthesize strJudgeName;
@synthesize searchedData;

@synthesize charRegistrationNo;
@synthesize charTicketNo;

@synthesize finalTry;
@synthesize array, array1;
@synthesize query, statement;

- (void)viewDidLoad {
   
    listData = [[NSMutableArray alloc] init];        //array which store actual data
    ticketNumbers = [[NSMutableArray alloc] init];    //array which store actual ticket numbers
   
    [listData addObject:@""];
    [listData addObject:@""];
   
    [ticketNumbers addObject:@""];
    [ticketNumbers addObject:@""];
       
    /*NSMutableArray *array = [[NSArray alloc] initWithObjects:@"", @"",
                      @"CD-5646", @"GF-4536", @"GH-6747", @"SF-3425", @"GH-7673", @"DF-3425",
                      @"JX-4343", @"RG-4545", @"FD-3456", @"FG-4556", @"JG-6745", @"FG-5654", @"JH-4356",
                      @"JX-4343", @"BN-4567", @"DF-2356", @"TY-4555", @"GH-4563", nil];
   
    NSMutableArray *array1 = [[NSArray alloc] initWithObjects:@"", @"",
                      @"1002", @"1003", @"1004", @"1005", @"1006", @"1007",
                      @"1034", @"1034", @"1004", @"1004", @"1004", @"1008", @"1006",
                      @"1056", @"1056", @"1034", @"1012", @"1098", nil];*/
   
    array=[[NSMutableArray alloc] init];
    array1=[[NSMutableArray alloc] init];
   
    [array addObjectsFromArray:listData];
    [array1 addObjectsFromArray:ticketNumbers];

       [super viewDidLoad];
   
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
   
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    self.listData = nil;
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


#pragma mark -
#pragma mark Table View Data Source Methods

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


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [array1 count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   
    static NSString *SimpleTableIdentifier = @"MyIdentifier";
        NSUInteger row = [indexPath row];
   
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
   
   // if (cell == nil) {
#ifdef __IPHONE_3_0
        // Other styles you can try
        // UITableViewCellStyleSubtitle
        // UITableViewCellStyleValue1
        // UITableViewCellStyleValue2
       
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: SimpleTableIdentifier] autorelease];
#else
        cell = [[[UITableViewCell alloc] initWithFrame::CGRectZero reuseIdentifier: SimpleTableIdentifier] autorelease];
#endif
       
        if(row !=0){
        CGRect nameLabelRect = CGRectMake(0, 5, 150, 15);
        UILabel *nameLabel = [[UILabel alloc] initWithFrame:nameLabelRect];
        nameLabel.textAlignment = UITextAlignmentLeft;
        nameLabel.text = @"Ticket No:";
        nameLabel.font = [UIFont boldSystemFontOfSize:14];
        [cell.contentView addSubview: nameLabel];
        [nameLabel release];
   
        CGRect colorLabelRect = CGRectMake(0,26, 150, 15);
        UILabel *colorLabel = [[UILabel alloc] initWithFrame:
                               colorLabelRect];
        colorLabel.textAlignment = UITextAlignmentLeft;
        colorLabel.text = @"Model No:";
        colorLabel.font = [UIFont boldSystemFontOfSize:14];
        [cell.contentView addSubview: colorLabel];
        [colorLabel release];
       
        CGRect nameValueRect = CGRectMake(150, 5, 200, 15);
        UILabel *nameValue = [[UILabel alloc] initWithFrame:
                              nameValueRect];
        nameValue.text = [array objectAtIndex:row];
        nameValue.font = [UIFont boldSystemFontOfSize:14];
        [cell.contentView addSubview:nameValue];
        [nameValue release];
       
        CGRect colorValueRect = CGRectMake(150, 25, 200, 15);
        UILabel *colorValue = [[UILabel alloc] initWithFrame:
                               colorValueRect];
        colorValue.text = [array1 objectAtIndex:row];
        colorValue.font = [UIFont boldSystemFontOfSize:14];
        [cell.contentView addSubview:colorValue];
        [colorValue release];
           
        }
       
   // }
   
    //NSUInteger row = [indexPath row];
    //cell.textLabel.text = [listData objectAtIndex:row];
    //cell.textLabel.font = [UIFont boldSystemFontOfSize:50];
   
/*#ifdef __IPHONE_3_0   
    if (row < 7)
        cell.detailTextLabel.text = @"Mr. Disney";
    else
        cell.detailTextLabel.text = @"Mr. Tolkein";*/
//#endif
    return cell;
   
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSUInteger row = [indexPath row];
    NSString *rowValue = [listData objectAtIndex:row];
   
    //Your code here

}

-(NSIndexPath *)tableView:(UITableView *)tableView
 willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    return indexPath;
}

- (void)dealloc {
    [array release];
    [ticketNumbers release];
    [array1 release];
    [listData release];
    [super dealloc];
}


@end

No comments: