Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9112001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:37:56+00:00 2026-06-17T03:37:56+00:00

I have a NSMutableArray in which I m storing items taken from service url

  • 0

I have a NSMutableArray in which I m storing items taken from service url and done parsing.I m showing the array items in UITableView acting like gridview(4 columns in each row and no of rows depends on array count).It is something like showing all the online exam slots available in a week.So I have to load each day timings one by one and if all the slots are reserved for a particular day then should display a msg for that day (No slot available) and then load the next array items in a tableView. But I m able to get only the last day slots available.

I have to get in the following format:

10/1/2013

10:00 AM    11:00 AM   12:00 PM   1:00 PM
2:00 PM

11/1/2013

11:00 AM     12:00 PM   1:00 PM    2:00 PM 

12/1/2013

   No slot available

13/1/2013

10:00 AM    11:00 AM   12:00 PM   1:00 PM
2:00 PM     3:00 PM

............

As of now I m using a same tableview and loading each array items for a particular day seprately.But I m able to get only the last day timings

How can I get in this particular format?

Any suggestions/advices would be appreciable on which control to use or how to use the same tableView would be appreciable.

EDIT:

-(void)LoadWeekSlots
{

    for(int i=0;i<7;i++)
    {

      NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

        NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
        [offsetComponents setDay:i];
        NSDate *nextDate = [gregorian dateByAddingComponents:offsetComponents toDate: [NSDate date] options:0];
        [offsetComponents release];
        [gregorian release];
        NSLog(@"%@",nextDate);

        NSDateFormatter *df=[[[NSDateFormatter alloc]init] autorelease];
        df.dateFormat = @"yyyy-MM-dd";
        getdateinmmformat=[[NSString stringWithFormat:@"%@",[df stringFromDate:nextDate]] componentsSeparatedByString:@""];
        NSLog(@"%@",getdateinmmformat);
        result=[[getdateinmmformat valueForKey:@"description"] componentsJoinedByString:@""];
        weekdayString=[nextDate descriptionWithCalendarFormat:@"%A" timeZone:nil locale:[[NSUserDefaults standardUserDefaults]dictionaryRepresentation]];
        NSLog(@"Day :%@",weekdayString);
        selectedtableView=i;
        [self LoadSlots];
        NSLog(@"%@",arr1);
   }
}

-(void)LoadSlots{

// calling the service url and taking the values in NSMutableArray (arr1)
     [self CheckArray];

}


-(void)CheckArray{


    NSMutableArray *yourArray = [[NSMutableArray alloc] init];

    for (NSDictionary *dict in arr3) {

        NSString *str=[dict valueForKey:@"Code"];

        NSString*newstr=  [str stringByReplacingOccurrencesOfString:@"," withString:@""];

        [yourArray addObject:newstr];

    }

    BOOL isTheObjectThere = [yourArray containsObject:weekdayString];

    if([arr1 count]==0 && isTheObjectThere==YES)
    {

        displayError  =[[UILabel alloc]init];
        [displayError setFrame:CGRectMake(0,390,320,200)];
        displayError.textAlignment=UITextAlignmentLeft;
        displayError.backgroundColor=[UIColor clearColor];
        NSString *string1=@" No slot available.";
       displayError.text=[NSString stringWithFormat:@"%@ ",string1];
       displayError.textColor=[UIColor redColor];
        displayError.shadowColor=[UIColor blackColor];
        displayError.font=[UIFont fontWithName:@"Verdana-Italic" size:14];
        [testscroll addSubview:displayError];
       float fscrview =displayError.frame.origin.y + displayError.frame.size.height+ 60;
        testscroll.contentSize=CGSizeMake(320, fscrview);

    }


    else
    {
      sections=[[NSMutableArray alloc] init];
        for(int s=0;s<1;s++)
          {
            NSMutableArray *section=[[NSMutableArray alloc] init];
             for(int i=0;i<[arr1 count];i++)
                {
                    Item *item=[[Item alloc] init];
                    NSString *eventName=[[arr1 objectAtIndex:i]objectForKey:@"TimeStart"];

                    item.TimeStart=eventName;
                    [section addObject:item];

                }
                [sections addObject:section];

            }




            self.tableView=[[UITableView alloc]initWithFrame:CGRectMake(0,390,320,[arr1 count]*40) style:UITableViewStylePlain];
            self.tableView.delegate = self;
            self.tableView.dataSource = self;
            self.tableView.scrollEnabled=NO;
            [testscroll addSubview:self.tableView];
            [self.tableView reloadData];
             self.tableView.frame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.tableView.contentSize.height);
            float fscrview = self.tableView.frame.origin.y + self.tableView.frame.size.height + 10;
            testscroll.contentSize=CGSizeMake(320, fscrview);
            testscroll.scrollEnabled=YES;
            }

        }

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSMutableArray *sectionItems=[sections objectAtIndex:indexPath.section];
    int numRows=[sectionItems count]/4;
    if(numRows==0)
    {
        return 80;
    }

    else
    {

        NSArray* items = [sections objectAtIndex:indexPath.section];
        int total = [items count];
        float f = (float)total /4;
        int numberOfGridRows = ceilf(f);
        NSLog(@"\n\n Rows :>> %d",numberOfGridRows);
        if(numberOfGridRows==1)
        {
            return numberOfGridRows * 100.0;

        }

        else if(numberOfGridRows==2)
        {
            return numberOfGridRows * 70.0;

        }
        else if(numberOfGridRows==3)
        {
            return numberOfGridRows * 60.0;

        }
        else if(numberOfGridRows==4)
        {

            return numberOfGridRows * 70.0;

        }
        if(numberOfGridRows>4 && numberOfGridRows<8)
        {
             return numberOfGridRows * 65.0;


        }
        else
        {
          return numberOfGridRows * 40.0 ;
        }



    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *hlCellID=@"hlCellID";

    UITableViewCell* hlcell=[tableView dequeueReusableCellWithIdentifier:hlCellID];

    if(hlcell == nil)
    {
        hlcell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault    reuseIdentifier:hlCellID]autorelease];

        hlcell.accessoryType = UITableViewCellAccessoryNone;
        hlcell.selectionStyle = UITableViewCellSelectionStyleNone;    
    }
    int section=indexPath.section;
    NSMutableArray *sectionItems=[sections objectAtIndex:section];
    int n=[sectionItems count];
    int i=0,i1=0;
    while(i<n)
    {
        int yy= 4+i1*34;
        int j=0;
        for(j=0;j<4;j++)
        {
            if(i>=n)break;
           Item *item=[sectionItems objectAtIndex:i];
            CGRect rect=CGRectMake(0+70*j,yy,79,40);
            UIButton *button=[[UIButton alloc] initWithFrame:rect];
            [button setFrame:rect];
            [button setContentMode:UIViewContentModeLeft];
            button.titleLabel.font = [UIFont systemFontOfSize:14];
            NSString *settitle=[NSString stringWithFormat:@"%@",item.TimeStart];
            [button setTitle:settitle forState:UIControlStateNormal];
            NSString *tagValue=[NSString stringWithFormat:@"%d%d",indexPath.section+1,i];
            button.tag=[tagValue intValue];
            [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [button setShowsTouchWhenHighlighted:YES];     
            [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
           [hlcell.contentView addSubview:button];
            [button release];
            i++;




        }
        i1=i1+1;
    }
    return hlcell;

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [sections count];
}   

This is the code I have done .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:37:58+00:00Added an answer on June 17, 2026 at 3:37 am

    try the some code from my this bellow code… remove some other code which not useful for you..

    i had this type of requirement and i complete it with my bellow code and logic… also see the image i think you want something like that…

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return [_grids count];
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return 1;
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    { 
        NSArray* items = [_grids objectAtIndex:indexPath.section];
        
        //number of rows in one grid if one row will have 4 items
        //    float totalRow = ceilf(items.count/4);
        int total = [items count];
        
        float f = (float)total /4;
        int numberOfGridRows = ceilf(f);
        NSLog(@"\n\n Rows :>> %d",numberOfGridRows);
        //height of table row
        return numberOfGridRows * 36.0 + 120;
    }
    
    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
    {
        return [NSString stringWithFormat:@"Grid %d", section];
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {    
        static NSString* cellIdentifier = @"gridCell";
    
        UITableViewCell *gridCell = [tableView dequeueReusableCellWithIdentifier:nil];
        
        if(gridCell == nil)        
        {
            gridCell =  [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
            
            gridCell.accessoryType = UITableViewCellAccessoryNone;
            
            gridCell.selectionStyle = UITableViewCellSelectionStyleNone;
            
        }
    //    UIImageView *img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"lion.jpg"]];
    //    [img setFrame:CGRectMake(0, 0, 320, 120)];
    //    [gridCell.contentView addSubview:img];
        
        UIImageView *imgUser = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"noImage.png"]];
        [imgUser setFrame:CGRectMake(5, 5, 100, 115)];
        [gridCell.contentView addSubview:imgUser];
        
        UILabel *lbl = [[UILabel alloc]init];
        lbl.text = @"Dr. P.R. Joshi";
        lbl.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
        [lbl setFrame:CGRectMake(110, 5, 200, 31)];    
        [gridCell.contentView addSubview:lbl];
    
        UILabel *lblAddress = [[UILabel alloc]init];
        [lblAddress setFrame:CGRectMake(110, 31, 200, 31)];        
        lblAddress.text = @"706,Atlanta Tower,Gulbai Tekra,Ahemdabad-007.";
        lblAddress.lineBreakMode = UILineBreakModeWordWrap;
        lblAddress.numberOfLines = 0;
        lblAddress.font = [UIFont fontWithName:@"Helvetica" size:12];
    //    CGSize sizeToMakeLabel = [lblAddress.text sizeWithFont:lblAddress.font]; 
        lblAddress.frame = CGRectMake(lblAddress.frame.origin.x, lblAddress.frame.origin.y, 
                                 200,[self calculateHeightOfTextFromWidth:lblAddress.text :lblAddress.font :200 :UILineBreakModeWordWrap] ); 
    
        lblAddress.textColor = [UIColor darkGrayColor];
    
        [gridCell.contentView addSubview:lblAddress];
        
        DYRateView *rateView = [[[DYRateView alloc] initWithFrame:CGRectMake(110, lblAddress.frame.origin.y + lblAddress.frame.size.height + 5, 160, 14)] autorelease];
        rateView.rate = 4.5;
        rateView.alignment = RateViewAlignmentLeft;
        [gridCell.contentView addSubview:rateView];
        
        UIImageView *imgArrow = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"left-arrow-right-md.png"]];
        [imgArrow setFrame:CGRectMake(300, 57, 12, 18)];
        [gridCell.contentView addSubview:imgArrow];
        
        NSArray* items = [_grids  objectAtIndex:indexPath.section];
        
        int imageIndex = 0;
        
        int yOffset = 4;
        
        while (imageIndex < items.count)        
        {
            int yPos =  7 + yOffset * 30;
            
            for(int i = 0; i < 4; ++i)
            {
                CGRect  rect = CGRectMake((0 + i * 80), yPos, 80, 31);
                
                if (imageIndex < [items  count]) {
                    
                    UIImageView* imageView = [self gridImageRect:rect forImage:[items objectAtIndex:imageIndex]];
                    
                    [gridCell.contentView addSubview:imageView];
                    [imageView release];
                    
                    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
                    button.frame = rect;
                    button.tag = imageIndex;
                    [button addTarget:self 
                               action:@selector(btnTemp_Clicked:)
                     forControlEvents:UIControlEventTouchDown];
                    
                    [button setTitle:[NSString stringWithFormat:@"Title %d%d%d",indexPath.section,indexPath.row,imageIndex] forState:UIControlStateNormal];
                    [button.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
    
    //                [button.titleLabel setTextColor:[UIColor blueColor]];
                    [button setTitleColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"circle03.jpg"]] forState:UIControlStateNormal ];                
                    [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted ];
                    
                    [button setNeedsDisplay];
                    
                    [gridCell.contentView addSubview:button];
                    
                    //            rect = CGRectMake(((80 * i)-4), (yPos+44), 80, 12);
                    //            
                    //            
                    //            
                    //            UILabel* label = [self descriptionOfImage:imageIndex inRect:rect];
                    //            
                    //            [gridCell.contentView addSubview:label];
                    //            
                    //            [label release];
                }
                ++imageIndex;
            }
            ++yOffset;
        }
        return gridCell;
    }
    
    -(float) calculateHeightOfTextFromWidth:(NSString*) text: (UIFont*)withFont: (float)width :(UILineBreakMode)lineBreakMode
    {
        [text retain];
        [withFont retain];
        CGSize suggestedSize = [text sizeWithFont:withFont constrainedToSize:CGSizeMake(width, FLT_MAX) lineBreakMode:lineBreakMode];
        
        [text release];
        [withFont release];
        
        return suggestedSize.height;
    }
    
    -(IBAction)btnTemp_Clicked:(id)sender{
        UIButton *btn = (UIButton *)sender;
        NSLog(@"Selected Image : %d  Button Title is ==>> %@",btn.tag,btn.titleLabel.text);
    }
    
    -(UIImageView *)gridImageRect:(CGRect)rect  forImage:(UIImage *)image
    {
        UIImageView* imageView = [[UIImageView alloc] initWithFrame:rect];
        imageView.image = image;
        
        return imageView;
    }
    
    -(UILabel *)descriptionOfImage:(int)imageNumber inRect:(CGRect)rect
    {
        UILabel *label = [[UILabel alloc] initWithFrame:rect];
        
        label.text = [NSString stringWithFormat:@"Image  %d", imageNumber + 1];
        
        label.textColor = [UIColor blackColor];
        
        label.backgroundColor = [UIColor clearColor];
        
        label.textAlignment = UITextAlignmentCenter;
        
        label.font = [UIFont fontWithName:@"ArialMT" size:12];
        
        return label;
    }
    

    See the screen shot which output of this code…

    enter image description here enter image description here

    Also See these bellow links for UIGridView Demo and tutorials..

    1. UIGridView

    2. GMGridView

      i hope this helpful to you…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming I have an NSMutableArray which is loaded from file: searchTermsArray = [[NSMutableArray alloc]
I have an NSMutableArray (detailsMA)having 100 strings like @True. Am storing that array in
I have created a class which has a static NSMutableArray, I want this array
I have an NSMutableArray which has five objects in it. I want to insert
I have an NSMutableArray which I assign with: NSMutableArray *newElements = [[NSMutableArray alloc] initWithObjects:self.currentScene.elements,
Essentially I have an NSMutableArray which contains several NSDictionaries . I wish to sort
Here's my current situation: I have a NSMutableArray named dictKeyArray which I assign a
All. I have a NSMutableArray , which name is dummyPerson. And it's element is
I have a Singleton which has an NSMutableArray containing a Class, the Class contains
I have a NSMutableArray which contains a few NSString objects. How can I test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.