开发者

avoid auto release of NSMutable array..... iphone app

I have a NSmutablearray after i read datas from it, i cant read the same data(index) again

Error: "EXC_BAD_ACCESS"

in interface

NSMutableArray *ticketList;


@property (nonatomic, retain) NSMutableArray *ticketList;

assigning value

self.ticketList = [NSMutableArray arrayWithArray:[results objectForKey:@"tickets"]];

reading value

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

    static NSString *CellIdentifier = @"ticketCell";
    ticketCell *cell = (ticketCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];



    if (cell == nil) {

        [self.cellNib instantiateWithOwner:self options:nil];
        cell = tmpCell;
        self.tmpCell = nil;



    }
    else {
        // Nothing to do here. Because in either way we change the values of the cell later.
    }

    cell.useDarkBackground = (indexPath.row % 2 == 0);
        // Configure the data开发者_如何学编程 for the cell.
    int rowID = indexPath.row;

        NSDictionary *currentTicket = [ticketList objectAtIndex:(int)(indexPath.row)];
    NSString *tikid = [currentTicket objectForKey:@"number"];
        cell.ticketID = [currentTicket objectForKey:@"number"];
        cell.ticketStatus = [currentTicket objectForKey:@"status"];
        cell.ticketOpenDate = [currentTicket objectForKey:@"oDate"];
        cell.ticketEndDate = [currentTicket objectForKey:@"eDate"];
        cell.ticketCategory = [currentTicket objectForKey:@"category"];
        cell.ticketPriority = [currentTicket objectForKey:@"priority"];
        cell.ticketInfo = [currentTicket objectForKey:@"info"]; 
    return cell;
}


You have to alloc array properly:

ticketList = [[NSMutableArray alloc] initWithArray:[results objectForKey:@"tickets"]];

And also maybe try to alloc currentTicket:

NSDictionary *currentTicket = [[NSDictionary alloc] initWithDictionary:[ticketList objectAtIndex:indexPath.row]];


Sounds like somewhere you're doing something like this:

[currentTicket release];

If so, don't. The currentTicket pointer doesn't belong to you.


use this

ticketList = [[NSMutableArray alloc]initWithArray:[results objectForKey:@"tickets"]];

instead of

self.ticketList = [NSMutableArray arrayWithArray:[results objectForKey:@"tickets"]];

use this

NSDictionary *currentTicket = [ticketList objectAtIndex:indexPath.row];

instead of

 NSDictionary *currentTicket = [ticketList objectAtIndex:(int)(indexPath.row)];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜