1

I am trying to create a table view in my view based application but I am facing a problem

NSArray *array = [[NSArray alloc] initWithObjects:@"iPod",forecast.desc,nil];
NSLog(@"this is the forecast routeNo = %@", forecast.desc);

As you can see this is the array that shows the values in the table, the result of this code is iPod (only), "forecast.desc" doesn't show anything knowing that forecast is an instance of another class and "desc" is a string in that class

and just to make sure forecast.desc shows the correct information in the log but in the table as if doesn't exist can anyone see where is the problem ?

Thanks

6
  • 1
    Does the NSLog call output the value of forecast.desc? Commented Jan 22, 2011 at 4:21
  • Try [[NSArray alloc] initWithObjects:@"iPod", [NSString stringWithString:forecast.desc], nil]; Commented Jan 22, 2011 at 4:21
  • yes NSLog output the value of forecast.desc, Simon, tried that before application crashes Commented Jan 22, 2011 at 4:24
  • Is forecast.desc a string? What is the output NSLog displays? I mean what is the actual string of forecast.desc contains? Commented Jan 22, 2011 at 4:29
  • @Simon: this is the output "Altavista - Gatinue" which is a String as you can see Commented Jan 22, 2011 at 4:32

2 Answers 2

1

Try

[[NSArray alloc] initWithObjects:@"iPod", [NSString stringWithFormat:@"%@",forecast.desc], nil];
Sign up to request clarification or add additional context in comments.

1 Comment

Thx man now am one step closer, it shows a null I have to figure that out, but now at least I know where is the problem
0

@bhappy the result of array variable is @"iPod" only means that forecast.desc has nil value.

So try to debug the code using single stepping and check what is the value of desc at the time of initializing the array.

And one more thing if desc is a member variable of class forecast than did you set the property for it, if not then forecast.desc wont work. You should check that first.

9 Comments

Alright you have a good point there, I did what you mentioned apparently stopping at the NSArray line forecast will show an address but forecast.desc will show "out of scope" so I can't see the value unless am not doing it right and still showing output in the NSLog
so that it means you have not set the property of desc and you trying to access the object in another class or you dont have any value inside and still trying to access it and it will give you EXC_BAD_ACCESS. so which one is it.
if you did not set the property (i m assuming you didnt) so you should write the getter and setter methods for that object
Yes I do have a property in the class that forecast is pointing to if thats what you mean "@property (nonatomic, retain) NSString *desc;"
did you alloc and init desc variable in the class were you are using it. or you are doing stringWithFormat:
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.