0

Am try to populate my table from core data and it give an error at this line

Tips *tipy = [arr objectAtIndex:indexPath.row];

here is my .m file

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return [arr count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[ UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    Tips *tipy = [arr objectAtIndex:indexPath.row]; 
    cell.textLabel.text = [tipy tipdescription];
    cell.detailTextLabel.text = [tipy.tipnumber stringValue];

    return cell;
}

app and arr is declared in the .h file as and also synthesized in the .m file

@property (nonatomic, retain) AppDelegate *app;
@property(nonatomic, assign) NSArray *arr;
1
  • 3
    what error do you have ? did you "#import Tips" in your file ? Did you synthesized the property ? if so you shoukd write "self.arr" instead of arr Commented Jul 21, 2012 at 9:36

2 Answers 2

5

As moxy said, you should write self.arr instead of arr. You have set @property(nonatomic, assaign) NSArray *arr; Did you synthesized those properties? Be sure to do that. And Try @property(nonatomic, retain) NSArray *arr; instead of @property(nonatomic, assaign) NSArray *arr;. The assaign does not increase the retain count thus there is a chance that the value can be autoreleased. Don't forget to release the arr in dealloc to avoid memory leak.

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

2 Comments

thanks alot. the problem was coz i did not use retain in my array
if this answer helped you, accept it. you should accept answers according to Stackoverflow FAQ
0

Just guessing, because there's not enough code to check, but NSManagedObjectContext's executeFetchRequest:error: does return autoreleased NSArray and your property arr is defined as assign, not strong/retain => your NSArray is released and arr points to trash. Maybe this is the cause, but as I said, there's not enough code to be sure.

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.