im a begginer Objective-c programmer and i stuck at this point. I Created an App from the View Template, then edited the view xib and add a button and assigned it to the showEdicoes function, but when i click it, it does execute the function(i tested with breakpoints) but it doesnt do anything, if i click again it gives an EXEC_BAD_ACESS
Codes:
bipViewControl开发者_开发技巧ler.h (the default one created by the template) #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 and edicoesVC.m are the TableViewController to which i wan to change to.
i didnt changed anything on the appDelegate what i missed? Thanks i advanceEDIT: Additional code 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
I suspect the EXEC_BAD_ACCESS arises from the line:
[self.EdVC release];
This is because you have declared EdVC as (nonatomic, retain) in the header. This will perform a release followed by a retain when it is assigned a new value but you are performing an extra release. Take out the [self.EdVC release]
line and move it to dealloc as:
[EdVC release];
Give this a try as it's the only thing I can think of, based on the code you've posted.
On the problem of nothing happening, I can't tell what's wrong from the code posted. Could you post the startup code of edicoesVC.h/edicoesVC.m
?
You are using "self.EdVC" which is what I believe is causing your problem. When you access properties, just use the property name. For example:
[EdVC release];
One more thing, when coding in Objective-C classes are usually capitalized (i.e., BipViewController) and variables are lower case, i.e., eDic).
精彩评论