Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
Hi guys, I am working on an app that uses the date to set off a chain reaction of events. All I need help with is the code to tell the iPhone to take today's date and display it as a label. Can anyone help with writing it? I am sure it is really simple but I can't find it anywhere! Thanks for future help! By the way I am a noobie at this but I am trying to get better by reading 3 books.
Nobody is going to write the code for you. Anyone considering doing it please don't, it's not going to help him learn. Plus Rick already practically wrote it for you.
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.
I can not understand the dateformatter part. I am trying to write this for my mom and I need it to be done by the end of july and this is the last of the code i need. From there it is just copying and pasting over and over.
This is what I have so far and I dont even know if it works because it is saying expected identifier or ( before { and i can not get past this { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"MMM dd"]; [formatter setDateStyle:NSDateFormatterMediumStyle];
Okay your code looks good except you need to run initWithFrame on the label and you'd be creating a new label every time. I advise creating the label in IB and hooking an IBOutlet up. Then you just need to put a method name to it, I'm surprised that you didn't know how to do that but you knew how to write all that code. Also code tags next time please.
[1/CODE] Without the 1. So this is what it would look like with the label being created in IB and having a name of dateLabel. [CODE] - (void)setDateLabelWithCurrentDate { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@\"MMM dd\"]; [formatter setDateStyle:NSDateFormatterMediumStyle];
I think the reason you get that error "expected identifier or ( before { " is because you didn't declare the method name at the front. --> If you follow what Domele said that should fix it.
I wish my skill is good enough and people start asking me to write code for them, at least not my mum ha ha.... Good luck and hope you meet your deadline...
Replies
2. Create an NSDateFormatter.
3. Set the date format of the NSDateFormatter object to whatever you want. You can find a list of format codes here: Stepcase Blog Archive Format String for the iPhone NSDateFormatter
4. Turn the date into a string using one of NSDateFormatter's methods. Specifically stringFromDate.
5. If done, release the NSDateFormatter.
New app - See screenshots and details at www.globaclock.com.
If you want to
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomethat will get you today's date.
then to display it you need to put it into a string using NSDateFormatter (and maybe NSDateFormatterLongStyle)
and finally something like:
datelabel.text = [df stringFromDate:today];
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomecould any of you write the code for me?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeNew app - See screenshots and details at www.globaclock.com.
If you want to
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI am trying to write this for my mom and I need it to be done by the end of july and this is the last of the code i need. From there it is just copying and pasting over and over.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeNew app - See screenshots and details at www.globaclock.com.
If you want to
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM dd"];
[formatter setDateStyle:NSDateFormatterMediumStyle];
NSString *dateToday = [formatter stringFromDate:[NSDate date]];
UILabel *dateLabel = [[UILabel alloc];
[dateLabel setText:dateToday];
[formatter release];
}
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeJust call the method like so:
whenever you want to set the label.
New app - See screenshots and details at www.globaclock.com.
If you want to
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI think the reason you get that error "expected identifier or ( before { " is because you didn't declare the method name at the front. --> If you follow what Domele said that should fix it.
I wish my skill is good enough and people start asking me to write code for them, at least not my mum ha ha....
Good luck and hope you meet your deadline...
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome