簡體   English   中英

從UIView更改為UITableView

[英]Change From a UIView to a UITableView

我是一個入門的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

我懷疑EXEC_BAD_ACCESS來自以下行:

[self.EdVC release];

這是因為您已在標頭中將EdVC聲明為(非原子性,保留)。 當為它分配了新值時,它將執行釋放操作,然后執行保留操作,但是您要執行額外的釋放操作。 取出[self.EdVC release]行,並將其移至dealloc為:

[EdVC release];

根據您發布的代碼,嘗試一下,這是我唯一能想到的事情。

在什么都沒有發生的問題上,我無法從發布的代碼中看出問題所在。 您可以張貼edicoesVC.h/edicoesVC.m的啟動代碼嗎?

您正在使用“ self.EdVC”,我認為這是造成您的問題的原因。 訪問屬性時,只需使用屬性名稱。 例如:

[EdVC release];

還有一點,當在Objective-C類中的編碼通常大寫(即BipViewController)而變量為小寫形式(即eDic)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM