tableView cellForRowAtIndexPath - 发送到解除分配的实例的消息

时间:2012-09-25 21:11:06

标签: iphone objective-c xcode tableview

每当我尝试从我的应用程序访问视图时,应用程序立即关闭。我捕获了激活NSZombieEnabled的日志。这是我得到的:

    *** -[RecargaOtroController tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0x604fd20
(gdb) info malloc-history 0x604fd20
Alloc: Block address: 0x0604fd20 length: 192
Stack - pthread: 0xa07c6540 number of frames: 38
    0: 0x955250a3 in malloc_zone_calloc
    1: 0x95524ffa in calloc
    2: 0x10a62d4 in class_createInstance
    3: 0xe725d8 in +[NSObject(NSObject) allocWithZone:]
    4: 0xe723da in +[NSObject(NSObject) alloc]
    5: 0x519c3b in -[UIClassSwapper initWithCoder:]
    6: 0x6039fd in UINibDecoderDecodeObjectForValue
    7: 0x6046ac in -[UINibDecoder decodeObjectForKey:]
    8: 0x51993e in -[UIRuntimeConnection initWithCoder:]
    9: 0x6039fd in UINibDecoderDecodeObjectForValue
   10: 0x6032f5 in UINibDecoderDecodeObjectForValue
   11: 0x6046ac in -[UINibDecoder decodeObjectForKey:]
   12: 0x518c36 in -[UINib instantiateWithOwner:options:]
   13: 0x51aab7 in -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:]
   14: 0x3d0628 in -[UIViewController _loadViewFromNibNamed:bundle:]
   15: 0x3ce134 in -[UIViewController loadView]
   16: 0x3ce00e in -[UIViewController view]
   17: 0x3cc482 in -[UIViewController contentScrollView]
   18: 0x3dcf25 in -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:]
   19: 0x3db555 in -[UINavigationController _layoutViewController:]
   20: 0x3dc7aa in -[UINavigationController _startTransition:fromViewController:toViewController:]
   21: 0x3d732a in -[UINavigationController _startDeferredTransitionIfNeeded]
   22: 0x3de562 in -[UINavigationController pushViewController:transition:forceImmediate:]
   23: 0x3d71c4 in -[UINavigationController pushViewController:animated:]
   24: 0x560e in -[RootViewController tableView:didSelectRowAtIndexPath:] at /Users/ipoletti/Documents/Recargame2/Recargame2/Classes/RootViewController.m:378
   25: 0x395b68 in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]
   26: 0x38bb05 in -[UITableView _userSelectRowAtPendingSelectionIndexPath:]
   27: 0x9d79e in __NSFireDelayedPerform
   28: 0xf2f8c3 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
   29: 0xf30e74 in __CFRunLoopDoTimer
   30: 0xe8d2c9 in __CFRunLoopRun
   31: 0xe8c840 in CFRunLoopRunSpecific
   32: 0xe8c761 in CFRunLoopRunInMode
   33: 0x17851c4 in GSEventRunModal
   34: 0x1785289 in GSEventRun
   35: 0x32cc93 in UIApplicationMain
   36: 0x2a3c in main at /Users/.../Documents/Recargame2/Recargame2/main.m:14
   37: 0x29cd in start

显然tableView是问题,但我无法弄清楚它有什么问题。应该如何在Interface Builder中链接? 我的.h:

    @interface RecargaOtroController : UIViewController <UINavigationControllerDelegate, UITableViewDataSource, UITableViewDelegate>{
        BOOL agrandaRecarga;
    }

    IBOutlet UITableView *tableView;
    @property (nonatomic, retain)IBOutlet UITableView *tableView;

UITextField *myLoc;
@property (nonatomic, retain)UITextField *myLoc;

这是关于tableView我的.m的一部分(我已将其合成):

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
    NSLog(@"TABLE VIEW: %@",tableView);
    NSLog(@"CELL");
    static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell==nil){
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease];
    }

    int r, g, b;
    b = 0x005C84 & 0x0000FF;
    g = ((0x005C84 & 0x00FF00) >> 8);
    r = ((0x005C84 & 0xFF0000) >> 16);
    UIColor *movistarColor = [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:100.0f];
    cell.detailTextLabel.font = [UIFont fontWithName:@"Verdana" size:15.0];
    cell.detailTextLabel.textColor = movistarColor;
    cell.textLabel.font = [UIFont fontWithName:@"Verdana-Bold" size:14.0];
    cell.textLabel.textColor = movistarColor;

    if([ListaNumerosController hayDefault]==nil){
        NSLog(@"NO HAY NUMEROS CARGADOS");
        if(indexPath.row == 0){
            cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ (%@)", tarjetaSeleccionada.alias, tarjetaSeleccionada.numero];
        }else if(indexPath.row == 1){
            cell.detailTextLabel.text = @"Otro";
        }else if(indexPath.row == 2){
            myLoc = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 250, 40)];
            myLoc.adjustsFontSizeToFitWidth = YES;
            myLoc.textColor = movistarColor;
            myLoc.textAlignment = UITextAlignmentLeft;
            myLoc.highlighted = NO;
            myLoc.clearsContextBeforeDrawing=YES;
            myLoc.placeholder = @"Ingrese su número";

            myLoc.delegate = self;
            myLoc.font = [UIFont fontWithName:@"Verdana" size:14.0];
            myLoc.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
            if(myLoc.text.length!=10){
                [myLoc becomeFirstResponder];
            }
            [myLoc setKeyboardType: UIKeyboardTypeNumberPad];
            [myLoc setEnabled:YES];
            [cell addSubview:myLoc];
        }else /*if(indexPath.row == 3)*/{
            cell.detailTextLabel.text = recarga.monto;
        }
    }else{
        NSLog(@"HAY NUMEROS CARGADOS");
        if(![telefonoSeleccionado.alias isEqualToString:@"Otro"]){
            NSLog(@"NO SE SELECCIONO OTRO NUMERO");
            if(indexPath.row == 0){
                cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ (%@)", tarjetaSeleccionada.alias, tarjetaSeleccionada.numero];
            }else if(indexPath.row == 1){
                cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ (%@)",telefonoSeleccionado.alias,[telefonoSeleccionado.telefono substringFromIndex:6]];
            }else if(indexPath.row == 2){
                cell.detailTextLabel.text = recarga.monto;
                myLoc.text = @"";
            }else if(indexPath.row == 3){
                cell.detailTextLabel.text = @"";
            }
        }else{
            NSLog(@"SE SELECCIONO OTRO NUMERO");
            if(indexPath.row == 0){
                cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ (%@)", tarjetaSeleccionada.alias, tarjetaSeleccionada.numero];
            }else if(indexPath.row == 1){
                cell.detailTextLabel.text = @"Otro";
            }else if(indexPath.row == 2){
                cell.detailTextLabel.text = @"";
            }else if(indexPath.row == 3){
                cell.detailTextLabel.text = recarga.monto;
            }
        }
    }

    return cell;

}

- (void)dealloc {
    [super dealloc];    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    // Start listening for updates when visable
   [tableView setDelegate:self];
    [tableView reloadData];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    // Stop listening for updates when not visable
    [tableView setDelegate:nil];
}

我认为问题可能出在Interface Builder文件中,有任何建议如何找出问题所在?

谢谢!

更新: 我的应用程序包含一个带有表格的主窗口。单击每一行时,您将转到另一个视图。新视图(RecargaOtroController)有另一个表。我使用另一个控制器以相同的方式实例化每个视图:

ThirdViewController.h

#import <UIKit/UIKit.h>


@interface ThirdViewController : UIViewController {

}

@end

ThirdViewController.m

#import "ThirdViewController.h"


@implementation ThirdViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
    [super viewDidUnload];
}


- (void)dealloc {
    [super dealloc];
}

然后,我的RootViewController是主屏幕:

RootViewController.h(摘录)

#import <UIKit/UIKit.h>

@interface RootViewController : UITableViewController <UIAlertViewDelegate, UINavigationControllerDelegate, UITableViewDataSource, UITableViewDelegate> {
    NSMutableArray *opcionesMenu;
    BOOL agrandaRecarga;
}

IBOutlet UITableView *tableView;
@property (nonatomic, retain)IBOutlet UITableView *tableView;

RootViewController.m(摘录)

ThirdViewController *detailViewController = nil;

if (indexPath.row == 1) {
            [self showConfirmaRecargaMessage];
            return;
        }else if (indexPath.row == 2) {
            detailViewController = [[RecargaOtroController alloc] initWithNibName:@"RecargaOtro" bundle:nil];
            detailViewController.title = @"Recargar otro número o monto";
        }else if (indexPath.row == 3) {

...

- (void)dealloc {
    [super dealloc];
}

我从来没有dealloc RecargaOtroController(也没有任何我正在实例化的屏幕类,无论如何,那些总是有效的。)

0 个答案:

没有答案