Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

I need your help please

meroumerou Posts: 5New Users
Hi all,
How can I group data of an object into sections that I got from database . In each section I must group only data that share the same "date". : date is an attribute of my object. How to implement ,numberOfRowsInSection , tableView cellForRowAtIndexPath and numberOfSectionsInTableView

Replies

  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,692Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    You should process the data before handing it off to the table view. You must come up with an algorithm to break the data up into groups, and then order them however you want. Your table delegate methods should not care at all about how you do that. See the table view link in my signature for guidance.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | SlickShopper 2 | Leave a PayPal donation
  • meroumerou Posts: 5New Users
    I tried But I didn't work , the problem is how to group these data in sections that share same date .
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,692Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    You tried what? Show your work.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | SlickShopper 2 | Leave a PayPal donation
  • meroumerou Posts: 5New Users
    On your exemple in the link , data that you populate are done staticly , for me data that I bring from database change all times
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,692Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    That's fine. Somewhere you have a method that receives that data. So don't send that data directly to the table view. Use some programming logic to arrange the data first. Then give it to the table view.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | SlickShopper 2 | Leave a PayPal donation
  • meroumerou Posts: 5New Users
    this what I did , if you have any suggestion for me , please help
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,692Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    edited April 2013
    Don't post file attachments. Copy-paste your code here. And use the code tags.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | SlickShopper 2 | Leave a PayPal donation
  • meroumerou Posts: 5New Users


    #import "GSAActivityViewController.h"
    #import "MHCActivityListCell.h"
    #import "UIColor+Additions.h"
    #import "MHCCaptionViewController.h"
    #import "GSAActivityViewController.h"
    #import "GSAAppDelegate.h"

    #import "ZMHC_PFEContact.h"


    #import "ZMHC_PFEActivities.h"


    @interface GSAActivityViewController ()
    {
    IBOutlet MHCActivityListCell *cellBundle;
    }

    @end

    @implementation GSAActivityViewController
    @synthesize contentView, activityTable;
    @synthesize activities , titleArray,taskList;

    - (void)viewDidLoad
    {

    [super viewDidLoad];

    NSMutableArray *array = [[NSMutableArray alloc] init];
    // arrayactivities is a liste that I bring from my syteme "SAP" ,here no problem
    ZMHC_PFEActivitiesList *arrayActivities = [ZMHC_PFEActivities findAll];
    NSLog(@dans didload activity);

    if ([arrayActivities length] > 0)
    {
    for (ZMHC_PFEActivities * oneRec in arrayActivities)
    {
    [array addObject:oneRec];
    NSLog(@%@",[oneRec VALID_FROM]);


    }
    }
    // activities is an array where i pur my objects
    NSLog(@apres affichage);
    self.activities = array;

    //NSLog(@%@",[self.activities count]);


    for (i = 0; i<[activities count]; i++) {
    id objet = [activities objectAtIndex:i];
    taskList2 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
    [NSArray arrayWithObjects:[NSDictionary

    dictionaryWithObjectsAndKeys:[objet CATEGORY_ID],@Activity,[objet VALID_FROM],@Date,nil]

    ],[objet VALID_FROM],nil];

    }
    self.taskList = taskList2;



    titleArray = [[NSArray alloc] initWithArray:[taskList

    keysSortedByValueUsingComparator:^NSComparisonResult(id obj1, id obj2)
    {
    NSString *date1 = [[(NSArray *)obj1

    objectAtIndex:0] objectForKey:@Date];
    NSString *date2 = [[(NSArray *)obj2

    objectAtIndex:0] objectForKey:@Date];
    return [date1 compare:date2];


    }]];
    }


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

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

    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {

    return [[taskList objectForKey:[titleArray objectAtIndex:section]] count];
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath

    *)indexPath {
    NSLog(@dans cellfrorowindexpath);
    [[NSBundle mainBundle] loadNibNamed:@MHCActivityListCell owner:self options:nil];
    MHCActivityListCell * cell = cellBundle;
    NSUInteger row = [indexPath row];
    ZMHC_PFEActivities *activity = [activities objectAtIndex:row];

    NSLog(@apres labeltext);

    cell.activityName.text = [[[taskList objectForKey:[titleArray

    objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView



    return [titleArray count];
    }



    - (NSString *)tableView:(UITableView *)tv titleForHeaderInSection:(NSInteger)section
    {
    return @05/04/2013;
    }

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {
    // create the parent view that will hold header Label
    UIView* customView = [[[UIView alloc] initWithFrame:CGRectMake(10,0,300,60)]

    autorelease];

    customView.backgroundColor = [UIColor colorWithRed:(18.0/255.0) green:(60.0/255.0)

    blue:(99.0/255.0) alpha:1.0];

    // create the label objects
    UILabel *headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
    headerLabel.backgroundColor = [UIColor clearColor];
    headerLabel.font = [UIFont boldSystemFontOfSize:18];
    headerLabel.frame = CGRectMake(70,2,200,20);

    // headerLabel.text = [titleArray objectAtIndex:section];
    headerLabel.textColor = [UIColor whiteColor];

    [customView addSubview:headerLabel];

    return customView;
    }
    @end
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,692Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    Hint: How To Make Your Code Look Nice

    Now then, simply posting code is of little use without further explanation. What is this code supposed to do? What does it actually do instead?
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | SlickShopper 2 | Leave a PayPal donation
  • RickSDKRickSDK Posts: 1,240Registered Users @ @ @ @
    what you should do is load all your data into global arrays. One array for each secion. You can do this is viewDidLoad. Then populate your table based on the arrays. Not based on core data.

    If your number of sections is dynamic, you can create a single global multidimentional NSMutableArray.
Sign In or Register to comment.