Здравствуйте. Я занимаюсь разработкой приложений для 4.1 и Xcode3.2.Мои приложения аварийно завершают работу при нажатии кнопки «Назад».При нажатии кнопки «назад» назад последний класс появляется немного, чем сбой, без ошибок или предупреждений .... Вот код .... сбой на функции возврата
#import "TransactionSummaryDetailViewController.h"
#import "TransactionSummaryData.h"
#import "Constant.h"
#import "DataBase.h";
#import "Common.h"
#import "YPCardHolderServiceService.h"
#import "SelectionScreenViewController.h"
@implementation TransactionSummaryDetailViewController
@synthesize table,cardReference;
@synthesize waitIndicator,transactionsummary,keyArray,valueArray,isSummaryAvailable;
@synthesize startDate,endDate;
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
-(void)getrowcount{
if(transactionsummary.cardholdernmae !=nil){
[keyArray addObject:@"Card Holder Name: "];
[valueArray addObject:transactionsummary.cardholdernmae];
}
if(transactionsummary.cardnumber!=nil){
[keyArray addObject:@"Card Number: "];
[valueArray addObject:transactionsummary.cardnumber];
}
if(transactionsummary.debittransactioncount != nil){
[keyArray addObject:@"Debit Tx. Count: "];
[valueArray addObject:transactionsummary.debittransactioncount];
}
if(transactionsummary.debittransactionvalue!=nil){
[keyArray addObject:@"Debit Tx. Value"];
[valueArray addObject:transactionsummary.debittransactionvalue];
}
if(transactionsummary.credittransactioncount!=nil){
[keyArray addObject:@"Credit Tx. Count: "];
[valueArray addObject:transactionsummary.credittransactioncount];
}
if(transactionsummary.credittransactionvalue!=nil){
[keyArray addObject:@"Credit Tx. Value: "];
[valueArray addObject:transactionsummary.credittransactionvalue];
}
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
appDelegate = [[UIApplication sharedApplication]delegate];
keyArray = [[NSMutableArray alloc]init];
valueArray = [[NSMutableArray alloc]init];
[self getrowcount];
NSLog(@"Key Array Count is %d",[keyArray count]);
[table setBackgroundColor:[UIColor clearColor]];
[table setSeparatorColor:TableViewCellSeperatorColor];
[waitIndicator setHidden:YES];
[self setTitle:@"Summary Details"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"list.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(BacktoView) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 76, 44)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
if(!isSummaryAvailable)
{
if([Common isNetworkAvailable])
{
[waitIndicator startAnimating];
YPCardHolderServiceService *services = [[YPCardHolderServiceService alloc] init];
YPTransactionsSummaryRequest *summaryRequest = [[YPTransactionsSummaryRequest alloc] init];
summaryRequest.SC = appDelegate.SC;
summaryRequest.userName = appDelegate.userName;
summaryRequest.valid =TRUE;
summaryRequest.cardReference =[NSString stringWithFormat:@"%@",cardReference];
NSLog(@"Start Date Is %@ and End Date is %@",startDate,endDate);
summaryRequest.startDate = startDate;
summaryRequest.endDate = endDate;
summaryRequest.applicationType = @"M";
[services getTransactionsSummary:self action:@selector(getTransactionsSummaryHandlers:) transactionsSummaryRequest:summaryRequest];
[summaryRequest release];
[services release];
}
}
[super viewDidLoad];
}
//Handle the Response of getTransactionsSummary
-(void)getTransactionsSummaryHandlers:(id) value
{
[waitIndicator stopAnimating];
// Handle errors
if([value isKindOfClass:[NSError class]]) {
NSLog(@"%@", value);
return;
}
// Handle faults
if([value isKindOfClass:[SoapFault class]]) {
NSLog(@"%@", value);
return;
}
// Do something with the YPLoginResponse* result
YPTransactionsSummaryResponse* result = (YPTransactionsSummaryResponse*)value;
if(result.statusCode == 0)
{
NSLog(@"Number of Transaction is =%d",[result.transactionSummaryList count]);
NSLog(@"Step 1 ='%@'",appDelegate.userID);
NSString *deleteQuery = @"delete from TransactionSummary where userid = ";
NSLog(@"Step 1 ='%@'",appDelegate.userID);
deleteQuery = [deleteQuery stringByAppendingString:[NSString stringWithFormat:@"%@ and cardreference = '%@'",appDelegate.userID,cardReference]];
NSLog(@"delete query= '%@'",deleteQuery);
[DataBase deleteDataFromTable:deleteQuery];
NSLog(@"delete query= '%@'",deleteQuery);
//for (int i =0; i< [result.transactionSummaryList count]; i++)
for (int i =0; i< [result.transactionSummaryList count] -2; i++)
{
NSLog(@"for loop= %d",i);
YPTransactionSummaryDetails *transactionSummary = (YPTransactionSummaryDetails*)[result.transactionSummaryList objectAtIndex:i];
NSLog(@"cardholdername= '%@'",transactionSummary.cardholderName);
/*NSString *insertQuery = @"Insert into TransactionSummary(cardholdername,cardnumber,debittransactioncount,debittransactionvalue,credittransactioncount,credittransactionvalue,userid) values(";
insertQuery =[insertQuery stringByAppendingString:[NSString stringWithFormat:@"'%@','xxxx xxxx xxxx %@',%d,%d,%d,%d,'%@',%@)",
transactionSummary.cardholderName,transactionSummary.cardNumber,transactionSummary.debitTransactionCount,
transactionSummary.debitTransactionValue,transactionSummary.creditTransactionCount,transactionSummary.creditTransactionValue,
appDelegate.userID]];*/
//Add by sarvesh
NSString *insertQuery = @"Insert into TransactionSummary(cardholdername,cardnumber,debittransactioncount,debittransactionvalue,credittransactioncount,credittransactionvalue,cardreference,userid) values(";
insertQuery =[insertQuery stringByAppendingString:[NSString stringWithFormat:@"'%@','%@',%d,%d,%d,%d,'%@',%@)",
transactionSummary.cardholderName,transactionSummary.cardNumber,transactionSummary.debitTransactionCount,
transactionSummary.debitTransactionValue,transactionSummary.creditTransactionCount,transactionSummary.creditTransactionValue,cardReference,
appDelegate.userID]];
NSLog(@"Insert Query for Transaction Summary is %@",insertQuery);
[DataBase InsertIntoTable:insertQuery];
}
//Read Update Data From DataBase and Refresh Table
NSString *query = @"Select * from TransactionSummary where userid = ";
query = [query stringByAppendingString:[NSString stringWithFormat:@"%@ and cardreference = '%@'",appDelegate.userID,cardReference]];
NSLog(@"select query= %@",query);
NSMutableArray *temp=[DataBase getTransactionSummaryTableData:query];
if([temp count] > 0)
{
transactionsummary = (TransactionSummaryData*)[temp objectAtIndex:0];
[keyArray removeAllObjects];
[valueArray removeAllObjects];
}
[self getrowcount];
[table reloadData];
}
}
-(void)viewDidAppear:(BOOL)animated
{
CGFloat navBarHeight = 50.0f;
CGRect frame = CGRectMake(0.0f, 20.0f, 320.0f, navBarHeight);
[self.navigationController.navigationBar setFrame:frame];
[super viewDidAppear:animated];
}
-(IBAction)BacktoView
{
NSLog(@"in back function..TrasactionSummaryDetail");
SelectionScreenViewController *screenView=[[SelectionScreenViewController alloc] initWithNibName:@"SelectionScreenViewController" bundle:nil];
[self.navigationController popViewControllerAnimated:YES];
[screenView release];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return cellHeightForGroupedTable;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(section == 0)
return [keyArray count];
else
return 0;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
NSString *title = nil;
switch (section){
case 0:{
//title = @"Summary Details";
break;
}
}
return title;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if ([self tableView:tableView titleForHeaderInSection:section] != nil) {
return tableHeaderHeight;
}
else {
// If no section header title, no section header needed
return 0;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}
// Create label with section title
UILabel *label = [[[UILabel alloc] init] autorelease];
label.frame = CGRectMake(20, 6, 300, 30);
label.backgroundColor = [UIColor clearColor];
label.textColor = HeaderTextColor;
label.shadowColor = HeaderTextShadowColor;
label.shadowOffset = CGSizeMake(0.0, 1.0);
label.font = HeaderTextFontSize;
label.text = sectionTitle;
// Create header view and add label as a subview
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320,60)];
[view autorelease];
[view addSubview:label];
return view;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = nil;
NSString *cellIdentifier;
cellIdentifier = @"SectionsTableIdentifier";
int row = [indexPath row];
CGRect nameLabelRect = CGRectMake(19 , 8, 240, 29);
CGRect cardlabelRect = CGRectMake(19,31,240,15);
UILabel *nameLabel = [[UILabel alloc] initWithFrame:nameLabelRect];
UILabel *cardnumber = [[UILabel alloc] initWithFrame:cardlabelRect];
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil){
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier] autorelease];
}
// Remove all subview from cell content view
for (UIView *view in cell.contentView.subviews){
[view removeFromSuperview];
}
[cell setAccessoryType:UITableViewCellAccessoryNone];
[nameLabel setTextColor:firstLabelFontColor];
[nameLabel setFont:firstLabelFont];
[nameLabel setFont:firstLabelFontSize];
nameLabel.textAlignment = UITextAlignmentLeft;
nameLabel.text = [NSString stringWithFormat:@"%@ : %@",[keyArray objectAtIndex:row],[valueArray objectAtIndex:row]];
[cell.contentView addSubview: nameLabel];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundColor:TableViewCellColor];
[nameLabel setBackgroundColor:[UIColor clearColor]];
[cardnumber setBackgroundColor:[UIColor clearColor]];
[cardnumber release];
[nameLabel release];
return cell;
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[table release];
[waitIndicator release];
[keyArray release];
[valueArray release];
[transactionsummary release];
[super dealloc];
}
@end