2

I'm Japanese so I'm not good at writing English.

So I hope people can understand what I'm trying to say otherwise I'll stuck for forever!!

I'm trying to create timer so I have object called Food.h which has:

@property (nonatomic,copy) NSString *text;

@property (nonatomic, assign) NSTimeInterval time;

also I have object called CategoryName.h which has:

@property (nonatomic, copy) NSString *name;

@property (nonatomic, strong) NSMutableArray *items;

and I am doing this on my DataModel.h:

@property (nonatomic, strong) NSMutableArray *lists;

then on my DataModel.m: self.lists = [[NSMutableArray alloc]initWithCapacity:20];

CategoryName *categoryName;

Food *food;

categoryName = [[CategoryName alloc]init];
categoryName.name = @"Spagettie";

categoryName.items = [[NSMutableArray alloc] initWithCapacity:20];

Food *food;

food = [[Food alloc]init];

food.text = @"Spaghetti";
food.time = 600;
[categoryName.items addObject:food];

all Food, CategoryName, DataModel are subclass of NSObject.

and, I have this method to set my timer's time:

- (void)setCountDownTime:(NSTimeInterval)time
{

    timeUserValue = (time < 0)? 0 : time;

    timeToCountOff = [date1970 dateByAddingTimeInterval:timeUserValue];

    [self updateLabel];

}

In my TimerViewController.h file, I put:@property (nonatomic, strong) Food *food; so I do TimerViewController.m file :

self.title = self.food.text 

[timer setCountDownTime:self.food.time];

title will works for this but for my timer label, it won't show any error however my label doesn't change.

If I do

[timer setCountDownTime:600];

it works. So please tell me what I'm doing wrong!

MANA
  • 33
  • 4
  • You should probably post the `updateLabel` method. – pNre Apr 08 '14 at 12:19
  • Also check whether `self.food.time` has value or it is nil? – Macrosoft-Dev Apr 08 '14 at 12:20
  • Thank you for suggestion. I'm updating label inside method of setCountDown: but should I update label again? – MANA Apr 08 '14 at 12:21
  • 1
    Where have you assigned `self.food` property? I do not see that in your code. – Amar Apr 08 '14 at 12:21
  • Thank you guys! I'm doing @property (nonatomic, strong) Food *food; on my .h of timer view controller – MANA Apr 08 '14 at 12:24
  • I'm doing food.time = 600 so it should have value, no? Sorry I'm very beginner of Objective-C and I'm try to understand English. – MANA Apr 08 '14 at 12:27
  • I tried everything but still not working... – MANA Apr 08 '14 at 12:34
  • the problem is not in the code you posted --> post more code – jimpic Apr 08 '14 at 12:44
  • If you have already declared `@property (nonatomic, strong) Food *food;` in your .h, then you are overriding it with a local declaration in your code when you do `Food *food;` Remove this line and always refer to food as `self.food` in your implementation file. – Stonz2 Apr 08 '14 at 12:57
  • Sorry I add more code. Thank you for suggestion. I hope it make better. – MANA Apr 08 '14 at 13:13
  • @MANA You are correctly declaring property for `food` in `TimerViewController` class. But you are not assigning anything to it. In your code you should have somewhere `timerViewController.food = ` or in view controller class itself `self.food = `. I do not see that done anywhere, so that property is `nil`(I think. Use `NSLog` to print `self.food` value). You getting my point? – Amar Apr 08 '14 at 13:29
  • Thank you Amar! I put NSTimeInterval _times; on TimerViewController class and I did _times = self.food.time then I did [_timer setCountDownTime:_times] still does not work. am I not doing what you are saying? Sorry for not understanding! but I appreciate your help. – MANA Apr 08 '14 at 13:41
  • I checked with writing NSLog and now I know I'm passing nil value but I don't know how I can fix it. – MANA Apr 08 '14 at 13:58
  • You need to use something like [this](http://stackoverflow.com/a/16261742/2713079) – itsji10dra Nov 26 '14 at 11:08

0 Answers0