Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 02-06-2010, 03:07 PM   #10 (permalink)
flyingguitar
Registered Member
 
flyingguitar's Avatar
 
Join Date: Feb 2010
Location: New Jersey
Posts: 10
flyingguitar is on a distinguished road
Default

but then why is it crashing?

EDIT: nvm, I found that the reason for the crashing was the for loops, I calculated 7,800 loops for each time the button was pressed, that might be a little too much for the iPhone to handle, I'll try to reduce that and see how that effects the performance.

EDIT2: FIXED DD I'll post the new code below to show how I resolved the problem (just in case you cared XD)

and btw, I don't plan on release this on the appstore, so it doesn't matter if I used the private API, but thanks for the tip anyway, I'll try to get into the habit of not using those.

Code:
#import "iEncryptViewController.h"
#import "table.h"
#import <iostream>
#import <string>
#define MAXLENGTH 30

@implementation iEncryptViewController

-(IBAction)encrypt {
	UIAlertView *ealert = [[UIAlertView alloc]initWithTitle:@"Encrypt" message:@"Enter Text to encrypt" delegate:self cancelButtonTitle: nil otherButtonTitles:@"Encrypt", nil];
	[ealert addTextFieldWithValue:nil label:@""];
	[[ealert textField] setDelegate:self];
	[[ealert textField] setKeyboardType:UIKeyboardTypeDefault];
	[[ealert textField] setKeyboardAppearance:UIKeyboardAppearanceDefault];
	[[ealert textField] setReturnKeyType:UIReturnKeyDone];
	[[ealert textField] setAutocorrectionType:UITextAutocorrectionTypeNo];
	ealert.tag = 1;
	[ealert show];
	[ealert release];
	
}

-(IBAction)decrypt {
	UIAlertView *dalert = [[UIAlertView alloc]initWithTitle:@"Decrypt" message:@"Enter Text to decrypt" delegate:self cancelButtonTitle: nil otherButtonTitles:@"Decrypt", nil];
	[dalert addTextFieldWithValue:nil label:@""];
	[[dalert textField] setDelegate:self];
	[[dalert textField] setKeyboardType:UIKeyboardTypeDefault];
	[[dalert textField] setKeyboardAppearance:UIKeyboardAppearanceDefault];
	[[dalert textField] setReturnKeyType:UIReturnKeyDone];
	[[dalert textField] setAutocorrectionType:UITextAutocorrectionTypeNo];
	dalert.tag = 2;
	[dalert show];
	[dalert release];
	
}

using namespace std;


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
	if (alertView.tag == 1) {
		if ((([[alertView textField] text].length) > 0) && (([[alertView textField] text].length) < MAXLENGTH)) {
		NSString *temp = [[alertView textField] text];
		string phrase = [temp cString];
		int a;
		int b = ([[alertView textField] text].length);
	for (a=0; a < b; a++) {
		char have;
		int tabe;
		have = phrase[a];
		for (tabe=0; tabe < 26; tabe++)
		{
			if (table[0][tabe] == have){
				phrase[a] = (table[17][tabe]);
				break; }
			else if (table[1][tabe] == have){
				phrase[a] = (table[18][tabe]);
				break; }
			else if (table[2][tabe] == have){
				phrase[a] = (table[19][tabe]);
				break; }
			else
				continue;
		}
	}
		const char* tempt = phrase.c_str();
		NSString *ans = [[NSString alloc] initWithCString: tempt];
		UIAlertView *anse = [[UIAlertView alloc] initWithTitle:@"Your encrypted message is:" message: ans delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
		[anse show];
		[anse release];
		[ans release];
		}
		else if (([[alertView textField] text].length) > MAXLENGTH) {
			UIAlertView *anse = [[UIAlertView alloc] initWithTitle:@"ERROR" message: @"The text you have entered is too long to be encrypted, try shortening the message." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
			[anse show];
			[anse release];
		}
	}	
	else if (alertView.tag == 2) {
		if ((([[alertView textField] text].length) > 0) && (([[alertView textField] text].length) < MAXLENGTH)) {
		NSString *temp = [[alertView textField] text];
		string phrase = [temp cString];
		int a;
		int b = ([[alertView textField] text].length);
		for (a=0; a < b; a++) {
			char have;
			int tabe;
			have = phrase[a];
			for (tabe=0; tabe < 26; tabe++)
			{
				if (table[17][tabe] == have){
					phrase[a] = (table[0][tabe]);
					break; }
				else if (table[18][tabe] == have){
					phrase[a] = (table[1][tabe]);
					break; }
				else if (table[19][tabe] == have){
					phrase[a] = (table[2][tabe]);
					break; }
				else
					continue;
			}
		}
		const char* tempt = phrase.c_str();
		NSString *ans = [[NSString alloc] initWithCString: tempt];
		UIAlertView *anse = [[UIAlertView alloc] initWithTitle:@"Your decrypted message is:" message: ans delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
		[anse show];
		[anse release];
		[ans release];
		}
		else if (([[alertView textField] text].length) > MAXLENGTH) {
			UIAlertView *anse = [[UIAlertView alloc] initWithTitle:@"ERROR" message: @"The text you have entered is too long to be decrypted, try shortening the message." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
			[anse show];
			[anse release];
		}
	}
}

- (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 {
    [super dealloc];
}

@end

Last edited by flyingguitar; 02-06-2010 at 04:07 PM.
flyingguitar is offline   Reply With Quote
 

» Advertisements
» Online Users: 525
7 members and 518 guests
Domele, kasumar, manop_cs, Newbie123, RockBaby, SuperDietGenius, Thompson22
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,446
Threads: 94,031
Posts: 402,605
Top Poster: BrianSlick (7,978)
Welcome to our newest member, larueta13
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:30 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.