x-code objective-c
こちらで特定のページに遷移した後に前のページに戻ると落ちてしまうソースがあります。
他のページでは問題ないのですがこのページに遷移した後に戻ると何故か落ちてしまします。
エラーコードをみてみたのですが
----------------------------------------------------------------
プログラムはシグナルを受信しました:“EXC_BAD_ACCESS”。
(gdb)
----------------------------------------------------------------
となっており何が原因かわかりませんでした・・・。
http://d.hatena.ne.jp/kacchi0516/20100212/1265906746
こちらのサイトに乗っている方法を試してみると
----------------------------------------------------------------
*** -[CALayer retain]: message sent to deallocated instance 0x6077490
----------------------------------------------------------------
とでました。retainは変数を保持する?為の関数のようなのですが
今まで使ったことがなく他のページでは落ちてないのでこれが原因かがわかりません。
#import "MelodyViewController01.h"
#import "MelodyViewController02.h"
@implementation MelodyViewController01
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
data = [[NSMutableArray alloc] initWithObjects:
@"白白白",
@"青青青",
nil];
}
#pragma mark -
#pragma mark Table view data source
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [data count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
MelodyTableViewCell *cell = (MelodyTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[MelodyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
return cell;
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MelodyViewController02* viewActive;
viewActive = [[MelodyViewController02 alloc] init];
viewActive.melodyColor = [[NSString alloc] initWithString:[data objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:viewActive animated:YES];
[viewActive release];
}
#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 {
// [data release];
[super dealloc];
}
@end
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [data count];
}
の return を0にすると落ちたりはしませんでした。
長々とすみません…。
どうやってもこの不具合が取れないので質問させて頂きました。