0

i have an UITableView and im trying to return the number of rows using [arrayName count] however when i run the application it seems to be crashing with no errors showing in console. Here is some code .. (also when i test the array in ViewDidLoad using NSLog, it does return '16' so im not sure why it crashes when i do the row count. Thanks ..

3 Answers 3

1

I think the problem is in this line:

elements  = [xpathParser search:@"//div[starts-with(@id,'content_div')]//a"];

I guess the - search method returns an autoreleased object, so that your elements object receives the release message after the method viewDidLoad returns and hence gets deallocated.

You can fix this in two ways:

  • add a retain call, like this

    elements = [[xpathParser search:@"//div[starts-with(@id,'content_div')]//a"] retain];

  • use properties, like this

    self.elements = [xpathParser search:@"//div[starts-with(@id,'content_div')]//a"];

Sign up to request clarification or add additional context in comments.

Comments

1

You don't need to release htmldata as it is already autoreleased. Remove the [htmldata release]; line and it should work.

Also, you don't, ever, release an object after the [super dealloc] line. Bring the line [elements release]; before the super dealloc.

Comments

0

You don't do a retain on elements, and when you assign it, you assign it directly to the property, and don't go through the setter.

Try:

self.elements  = [xpathParser search:@"//div[starts-with(@id,'content_div')]//a"];

Also, don't forget to release it in the dealloc method.

Comments

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.