0

私は初心者のObjective-cプログラマーであり、この時点で立ち往生しています。ビューテンプレートからアプリを作成し、ビューxibを編集してボタンを追加し、それをshowEdicoes関数に割り当てましたが、クリックすると関数が実行されます(ブレークポイントでテストしました)が、何もしませんもう一度クリックすると、EXEC_BAD_ACESS が表示されます

コード:
bipViewController.h (テンプレートによって作成されたデフォルトのもの)

    #import <UIKit/UIKit.h>
#import "edicoesVC.h";
@interface bipViewController : UIViewController {
    edicoesVC *EdVC;
}
@property(nonatomic,retain)edicoesVC *EdVC;
- (IBAction) showEdicoes:(id)sender;

@end


bipViewController.m

#import "bipViewController.h"

@implementation bipViewController
@synthesize EdVC;

- (IBAction) showEdicoes:(id)sender {
    edicoesVC *Edic = [[edicoesVC alloc] initWithNibName:@"edicoesVC" bundle:[NSBundle mainBundle]];
    self.EdVC = Edic;
    [Edic release];
    [self.navigationController pushViewController:self.EdVC animated:YES];
    [self.EdVC release];
    }
.....
@end

edicoesVC.h と edicoesVC.m は、変更したい TableViewController です。

appDelegate で何も変更していませ
ん。見逃したものはありますか?
ありがとうございます 編集を進め

ます: 追加コード
bipAppDelegate.h

#import <UIKit/UIKit.h>

@class bipViewController;

@interface bipAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
   bipViewController *viewController;

    UINavigationController *navigationController;
}


@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet bipViewController *viewController;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

@end

bipAppDelegate.m

#import "bipAppDelegate.h"
#import "bipViewController.h"

@implementation bipAppDelegate

@synthesize window;
@synthesize viewController;
@synthesize navigationController;
#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

    // Add the view controller's view to the window and display.
    [self.window addSubview:viewController.view];
    [self.window makeKeyAndVisible];

    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
     */
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}


- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     See also applicationDidEnterBackground:.
     */
}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
}


- (void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
}


@end

edicoesVC.h

#import <UIKit/UIKit.h>


@interface edicoesVC : UITableViewController {

}

@end

edicoes.m

#import "edicoesVC.h"


@implementation edicoesVC


#pragma mark -
#pragma mark View lifecycle


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


#pragma mark -
#pragma mark Table view data source

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


// 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...
    if(indexPath.row == 0) {[cell setText:@"Janeiro 1918"];}

    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.row == 0)
    {

    }
}


#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 {
    [super dealloc];
}


@end
4

2 に答える 2

0

EXEC_BAD_ACCESSは次の行から発生していると思われます。

[self.EdVC release];

これは、ヘッダーでEdVCを(非アトミック、保持)として宣言したためです。これにより、リリースが実行され、新しい値が割り当てられたときに保持が続きますが、追加のリリースを実行しています。行を取り出して、次の[self.EdVC release]ようにdeallocに移動します。

[EdVC release];

あなたが投稿したコードに基づいて、私が考えることができるのはそれだけなので、これを試してみてください。

何も起こらないという問題については、投稿されたコードから何が悪いのかわかりません。のスタートアップコードを投稿していただけませedicoesVC.h/edicoesVC.mんか?

于 2011-03-17T02:32:11.703 に答える
-1

あなたは「self.EdVC」を使用していますが、これが問題の原因であると私は信じています。プロパティにアクセスするときは、プロパティ名だけを使用してください。例えば:

[EdVC release];

もう 1 つ、Objective-C クラスでのコーディングは通常大文字で (BipViewController など)、変数は小文字 (eDic など) です。

于 2011-03-16T23:00:25.740 に答える