Изменить с UIView на UITableView - PullRequest
0 голосов
/ 17 марта 2011

Я начинающий программист 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

Ответы [ 2 ]

0 голосов
/ 17 марта 2011

Я подозреваю, что EXEC_BAD_ACCESS возникает из строки:

[self.EdVC release];

Это потому, что вы объявили EdVC как (неатомный, сохраняемый) в заголовке.Выполняется освобождение с последующим сохранением, когда ему присваивается новое значение, но вы выполняете дополнительное освобождение.Выньте строку [self.EdVC release] и переместите ее в dealloc как:

[EdVC release];

Попробуйте, так как это единственное, что я могу придумать, основываясь на опубликованном вами коде.

По вопросу о том, что ничего не происходит, я не могу сказать, что не так из опубликованного кода.Не могли бы вы опубликовать код запуска edicoesVC.h/edicoesVC.m?

0 голосов
/ 17 марта 2011

Вы используете "self.EdVC", что, как я считаю, вызывает вашу проблему.Когда вы получаете доступ к свойствам, просто используйте имя свойства.Например:

[EdVC release];

Еще одна вещь, когда кодирование в классах Objective-C обычно пишется с большой буквы (т. Е. BipViewController), а переменные в нижнем регистре, т. Е. EDic).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...