0

我会为这个解决方案变得有点疯狂.. 我有一个TableView和他的项目列表(来自 csv Parsing 的数组),当我选择时,我需要从这个数组传递一些数据到Detail TableView的列表一个细胞。。

我尝试了一些解决方案并尝试了它们,但这应该是最好的解决方案,并且代码符合指南。但是当我选择一个单元格时,我有一个“ EXC_BAD_ACCESS ”但我不明白僵尸在哪里对象,所以我发布所有课程:

#import "inRaggioViewController.h"
#import "iR-DetailViewController.h"


@implementation inRaggioViewController

@synthesize lista, record;


- (void)viewDidLoad {
    [super viewDidLoad];

    NSMutableArray *listaNonOrdinata = [[NSMutableArray alloc]init];
    self.navigationItem.title = @"Tipologia";

    NSString *fileString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Lista1" ofType:@"csv"] encoding:NSUTF8StringEncoding error:nil];
    record = [fileString csvRows];

    dettaglio = [[NSMutableArray alloc]init];
    id doppio = nil;

    for (int i=1; i < record.count; i++) {
        for (int j=0; j < listaNonOrdinata.count; j++) {
            doppio = [[record objectAtIndex:i] firstObjectCommonWithArray:listaNonOrdinata];
            if (doppio == nil) {
//              [dettaglio addObject:[NSNumber numberWithBool:NO]];
            } else {
//              [dettaglio addObject:[NSNumber numberWithBool:YES]];
            }
        }
        if (doppio == nil) {
            [listaNonOrdinata addObject:[[record objectAtIndex:i]objectAtIndex:0]];
        }
    }

    //Ordino array in ordine alfabetico
    lista = [[NSArray alloc]init];
    lista = [listaNonOrdinata sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

    [listaNonOrdinata release];
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return lista.count;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...
    NSString *cellValue = [lista objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue;

//  NSLog(@"dettaglio bool Value: %s",[[dettaglio objectAtIndex:indexPath.row]boolValue] ? @"YES" : @"NO");

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
    NSLog(@"Selezionata riga %i",indexPath.row+1);
        iR_DetailViewController *detailViewController = [[iR_DetailViewController alloc]init];
        // ...
        // Pass the selected object to the new view controller.
        detailViewController.navigationItem.title = [self.lista objectAtIndex:indexPath.row];
        [detailViewController.lista addObject:[[self.record objectAtIndex:indexPath.row+1]objectAtIndex:1]];
        [self.navigationController pushViewController:detailViewController animated:YES];
        [detailViewController release];
}


#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Relinquish ownership any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}


- (void)dealloc {
    [dettaglio release];
    [record release];
    [lista release];
    [super dealloc];
}


@end

奇怪的是列表对象在其他方法中工作正常,只是在选择方法中它给出了问题......

对不起我的英语不好,我英语说得不好。非常感谢您的建议!

我已经解决了! 多亏了大家,问题是我必须在 viewDidLoad 的末尾保留列表和记录对象!

4

1 回答 1

0

如果您尝试添加的列表是 NSArray,它将不起作用。如果它是 NSMutableArray,则只能添加它。试试看?

于 2013-07-29T16:52:36.930 回答