0

我有一个难以解决的问题。

单击上表中的单元格时,我应该打开一个新UITableView单元格。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

ChoiceChampionViewController *choiceChampionViewController = [[ChoiceChampionViewController alloc] initWithNibName:@"ChoiceChampionViewController" bundle:nil];

NSString * ind = @".....";
NSString * number = ..;
ind = [ind stringByReplacingOccurrencesOfString:@"XX" withString:number];
[[NSUserDefaults standardUserDefaults] setValue:number forKey:@"Region"];
choiceChampionViewController.url = ind;
[self.view addSubview: choiceChampionViewController.view];
}

ChoiceChampionViewController的结构如下:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {        
        champion = [[NSMutableArray alloc] init ];
        self.navigationItem.title = @"Here is some text to make the navBar big";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    dispatch_async(kBgQueue, ^{
        NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
        [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
    });
}

- (void)fetchedData:(NSData *)responseData {
   Method for process data
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [champion count];
}

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    League * app = [[League alloc] init];
    app = [champion objectAtIndex:[indexPath row]];
    cell.textLabel.text = app.title;

    return cell;
}

但它一直给我这个错误:[ChoiceChampionViewController tableView:cellForRowAtIndexPath:]: message sent to deallocated instance。我们能帮帮我吗?

4

1 回答 1

0

打开那个新的UITableViewControllerUIViewController使用pushViewControllerfor 进入新的UIViewController,如下所示......

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;{

    ChoiceChampionViewController * choiceChampionViewController = [[ChoiceChampionViewController alloc]initWithNibName:@"ChoiceChampionViewController" bundle:nil];
    UIBarButtonItem *_backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = _backButton;
    [_backButton release],
    _backButton = nil;

    [self.navigationController pushViewController:choiceChampionViewController animated:YES];
    [choiceChampionViewController release];
}

更新 :

也使用这种波纹管结构的cellForRowAtIndexPath:方法......

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }
    League * app = [[League alloc] init];
    app = [champion objectAtIndex:[indexPath row]];
    cell.textLabel.text = app.title;

    return cell;
}
于 2013-08-05T12:06:07.993 回答