Question

Here is my problem I had a table view which consists of 3 three labels in it (test1, test2, test3) which comes from webservice. I want to load all the three labels in a single table view. Here is my code below :

for (NSDictionary *entry in entries) {
                     projectNames = [entries valueForKey:@"NM_PROJECT"];
                     taskNames = [entries valueForKey:@"TASk_NAME"];
                     subtaskNames = [entries valueForKey:@"SUBTASK_NAME"];
                 }
                 NSLog(@"project : %@", projectNames);
                 NSLog(@"taskNames : %@", taskNames);
                 NSLog(@"subtask : %@", subtaskNames);
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [projectNames count];

}

-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identitifier = @"Cell";
    DLPTSTableViewCell * cell = [tableView
                                 dequeueReusableCellWithIdentifier:identitifier
                                 forIndexPath:indexPath];
    long row = [indexPath row];
    cell.textLabel.text = projectNames[row];
    cell.textLabel.text = taskNames[row];
    cell.textLabel.text = subtaskNames[row];

    return cell;


}

I want to load the test 1 in projectnames array, test 2 in tasknames array and test 3 in subtasks arrays..

Please help me out.

Was it helpful?

Solution

If you are creating custom UITableViewCell with name "DLPTSTableViewCell" then first create three labels i.e yourLabel1, yourLabel2, yourLabel3 and use this below code :

-(DLPTSTableViewCell *)getNewCell
{
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"DLPTSTableViewCell" owner:nil options:nil];
    DLPTSTableViewCell *cell;
    for (id currentObject in topLevelObjects)
    {
        if ([currentObject isKindOfClass:[DLPTSTableViewCell class]])
        {
            cell= (DLPTSTableViewCell  *)currentObject;
            return cell;
        }
    }
    return nil;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CustomCell";
    DLPTSTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        cell = [self getNewCell];
    }


    // for displaying values

    cell.yourLabel1.text = your first value;
    cell.yourLabel2.text = your second value;
    cell.yourLabel3.text = your third value; 

    return cell;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top