-1

I am using NSDate + Timeago to set time since now in detailLextLabel and it does not seem to be working I'm not sure why? I am retrieving the message from parse.com

My method:

PFObject *message = [self.messages objectAtIndex:indexPath.row];
cell.textLabel.text = [message objectForKey:@"senderName"];

NSDate *date = [message createdAt];


// I have tried this also
NSDate *date = [message objectForKey:@"createdAt"];
NSString *timeAgoString = [date timeAgo];
    cell.detailTextLabel.text = timeAgoString;

I want the detail text label to display ex. 5 mins ago

I'm getting null at the moment and nothing is displaying in detail text label

smithyy
  • 220
  • 2
  • 12

1 Answers1

1

I would recommend to use this NSDate-TimeAgo. After you include this extension to your project you will be able to generate string from date like this:

NSDate *date = [self.selectedMessage createdAt];
NSString *timeAgoString = [date timeAgo];
gontovnik
  • 690
  • 5
  • 9
  • so replace the NSTimeInterval with the NSString and pass in the timeAgoString in stringForTimeInterval? – smithyy Aug 22 '15 at 10:17
  • Yes. All you have to do is: `cell.detailedTextLabel.text = [[self.selectedMessage createdAt] timeAgo]`. If you do not get `[self.selectedMessage createdAt]` then check push settings, maybe something is not setup correctly. – gontovnik Aug 22 '15 at 10:17
  • i have tried it but it does not display a detailTextLabel at all – smithyy Aug 22 '15 at 10:49
  • Could you put a breakpoint before this line `cell.detailedTextLabel.text = [[self.selectedMessage createdAt] timeAgo]` and in write in debugger `po [self.selectedMessage createdAt]`? What did it show? After that, write in debugger `po cell.detailedTextLabel` and let me know what it shows. – gontovnik Aug 22 '15 at 10:51
  • i did this `NSDate *date = [self.selectedMessage createdAt]; NSString *timeAgoString = [date timeAgo]; cell.detailTextLabel.text = timeAgoString;` – smithyy Aug 22 '15 at 10:55
  • Then put a break point on line `cell.detailTextLabel.text = timeAgoString;` and write in debugger `po date` and `po timeAgoString` and let me know what it shows. – gontovnik Aug 22 '15 at 10:56
  • it says null in the log – smithyy Aug 22 '15 at 10:59
  • It means that **createdAt** in self.selectedMessage is null. Are you sure that this data is successfully loaded from parse? – gontovnik Aug 22 '15 at 11:00
  • Can you check whether **createdAt** is not null in parse.com database? – gontovnik Aug 22 '15 at 11:02
  • When you receive self.selectedMessage, do you get any other data from this model and only createdAt becomes null? – gontovnik Aug 22 '15 at 11:07
  • Hm, thats is really strange. If you want I can connect to your screen via TeamViewer and have a look. Otherwise email parse.com SDK support team, they will definitely help you with this issue. – gontovnik Aug 22 '15 at 11:12
  • hi i am not uploading any time to parse.com of when the message was created. how can i create that – smithyy Aug 22 '15 at 13:57
  • Why would you answer the question with a different 3rd party option then what the OP is asking about? – soulshined Aug 22 '15 at 14:00
  • In his question he said that it is seems that TTTTimeIntervalFormatter is not working, so I suggested him to try different third party library. Why? Is it bad to offer people alternatives? Then we discussed with him and found that issue is not related to that, issue is with createdAt value. – gontovnik Aug 22 '15 at 14:05
  • 1
    It's not bad @DanilGontovnik it just doesn't answer the question for that specific 3rd party option, so for future question seekers looking for an answer to that specific API won't get one, they'll get one for NSDate-TimeAgo and as you said, the issue has nothing to do with the API, it's his objects and values – soulshined Aug 22 '15 at 14:12