Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing date from array to sort UITableview by date
    text
    copied!<p>I have an array with the following information, retrieved from JSON:</p> <pre><code>Contents of events: ( "&lt;CalendarModel&gt; \n [title]: Arsenal v Man Utd\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-28T17:00:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Reading v QPR\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-28T14:30:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Newcastle v Liverpool\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-27T18:30:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: TBC\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-27T16:00:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Man City v West Ham\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-27T13:45:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Man Utd v Aston Villa\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-22T21:00:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Liverpool v Chelsea\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-21T17:00:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Spurs v Man City\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-21T14:30:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Fulham v Arsenal\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-20T16:00:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: West Ham v Man Utd\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-17T20:45:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Arsenal v Everton\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-16T20:45:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Chelsea v Man City\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-14T17:00:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Stoke v Man Utd\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-14T15:00:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Millwall v Wigan\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-13T18:15:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Reading v Liverpool\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-13T16:00:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: FC Basel v Spurs\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-11T21:05:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Rubin Kazan v Chelsea\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-11T21:05:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Juventus v Bayern Munich\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-10T20:45:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Barcelona v Paris St Germain\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-04-10T20:45:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Everton v Stoke\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-03-30T18:30:00.000+01:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Swansea v Spurs\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-03-30T16:00:00.000+01:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Sunderland v Man Utd\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-03-30T13:45:00.000+01:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Ireland v Austria\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-03-26T20:45:00.000+01:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Denmark v Bulgaria\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-03-26T20:15:00.000+01:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Sweden v Ireland\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-03-22T19:45:00.000+01:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Dennis McLaughlin\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-03-31T22:30:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Lee Thomas\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-03-30T23:00:00.000+01:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Lee Thomas\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-03-29T22:30:00.000+01:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Lee Thomas\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-03-28T21:30:00.000+01:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Lee Thomas\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-03-27T21:30:00.000+01:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Pat Kelly\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-02-14\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Ray Weaver\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-01-31\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Take the Biscuit\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-01-24\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: The McLaughlin Clan\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-01-18\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Local Artist\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-01-17\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Richie Vargas\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2013-01-10\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Tom Valbak\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2012-12-28\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Tom Brakl\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2012-12-25\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Tom Brakl\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2012-12-23\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Dessie Higgins\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2012-12-20\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Pat Kelly\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2012-12-13\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Rich Vargas\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2012-12-06\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Lee Thomas\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2012-11-22\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: International Jam Session\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2012-09-03T21:00:00.000+02:...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Kevin McKernan\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2012-08-30\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Lee Thomas\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2012-08-09\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Ray Weaver\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2012-07-19\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Gray Hawthorn\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2012-07-05\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Jimmy Walsh\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2012-06-07\\n [endTime]: 2...\n&lt;/CalendarModel&gt;", "&lt;CalendarModel&gt; \n [title]: Take The Biscuit\n [time]: (\n \"&lt;Time&gt; \\n [startTime]: 2012-11-29\\n [endTime]: 2...\n&lt;/CalendarModel&gt;" </code></pre> <p>I am trying to create the tableview with the startTime (only the date, not the hours and minutes) as the titleForHeaderInSection. The NSMutableArray containing the events is called events</p> <p>Can anybody help me in the right direction. As it stands now, i am getting data back with no headers, and just the events. I have the following right now, but I am still testing. This at least creates a header called Test</p> <pre><code> #pragma mark - table methods -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return events.count; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { CalendarModel* event = events[section]; NSString *dato = [[event.time objectAtIndex:0] startTime]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSzzz"; NSDate *gmtDate = [formatter dateFromString: dato]; formatter.dateFormat = @"dd-MM-yyyy"; dato = [formatter stringFromDate:gmtDate]; return dato; } -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CalendarModel* event = events[indexPath.row]; NSString *dato = [[event.time objectAtIndex:0] startTime]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSzzz"; NSDate *gmtDate = [formatter dateFromString: dato]; formatter.dateFormat = @"HH:mm"; dato = [formatter stringFromDate:gmtDate]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SportCell" forIndexPath:indexPath]; cell.textLabel.text = [NSString stringWithFormat:@"%@", event.title ]; cell.detailTextLabel.text = dato; return cell; } </code></pre> <p>Have edited the code above. It now works, but it is showing the same game every time. As if it always takes the first one, and shows that. I think the problem is in the </p> <pre><code>-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } </code></pre> <p>method.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload