Hey all,
I have a UITableView that displays various nsstrings from a custom object called a "Transaction." in CellForRowAtIndexPath it the allocates a new instance of a transaction and then copies the the values from a particular transaction that lives in the delegate array so I can access it from different views. It then uses the new transaction 'copy' and it's properties to popluate the table cell. The problem I'm having is if I release the copied transaction object when I go to redisplay the table the app crashes. if I comment out the release the program runs well, but I'm worried about memory management obviously. My question is what the heck should I do, is there another place to release this?
Here is the code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"TransCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
NSUInteger row = [indexPath row];
CashAppDelegate *mainDelegate = [(CashAppDelegate *) [UIApplication sharedApplication] delegate];
Transaction *cellTrans = [[Transaction alloc] init];
cellTrans = [mainDelegate.transactionArray objectAtIndex:row];
NSString *string = [NSString stringWithFormat:@"$%1.2f %@ | %@", cellTrans.amount, cellTrans.category, cellTrans.descriptionString];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.text = string;
//[cellTrans release];
return cell;
}