避免自动释放NSMutablearray ..... iphone应用程序

时间:2011-09-29 07:33:27

标签: iphone objective-c ios nsmutablearray

我有一个NSmutablearray 从我读取数据后,我再也无法读取相同的数据(索引)

错误: “EXC_BAD_ACCESS”

界面中的

NSMutableArray *ticketList;


@property (nonatomic, retain) NSMutableArray *ticketList;

分配值

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

阅读价值

      - (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;
}

3 个答案:

答案 0 :(得分:1)

使用此

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

而不是

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

使用此

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

而不是

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

答案 1 :(得分:1)

您必须正确分配数组:

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

也可以尝试分配currentTicket:

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

答案 2 :(得分:1)

听起来像你正在做的事情:

[currentTicket release];

如果是这样,请不要。 currentTicket指针不属于您。