十进制转换为16进制。
char tohex(int n)
{
if(n>=10 && n<=15)
{
return 'A'+n-10;
}
return '0'+n;
}
void dec2hex(int n,char *buf)
{
int i=0;
int mod;
while(n)
{
mod = n%16;
buf[i++]=tohex(mod);
n=n/16;
}
//得进行反序。
int j,k;
for(j=0,k=i-1;j<i/2;j++,k--)
{
char temp;
temp = buf[j];
buf[j] = buf[k];
buf[k] = temp;
}
buf[i]='\0';
}
//用NSUserDefaults 的时候,为了防止重新启动的时候上次存的值没有存上。应该在存值的时候synchronize一下,
NSData *encodedCurBirdSightingList = [NSKeyedArchiver archivedDataWithRootObject:self.masterBirdSightingList];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:encodedCurBirdSightingList forKey:@
"BirdSightingList"
];
[defaults synchronize];
if([Mjk insertMjk:mj] != 0){
_nextBtn.hidden = YES;
int temp = [[[NSUserDefaults standardUserDefaults]objectForKey:@"mliushui"]intValue];
if (temp == 65536) {
[[NSUserDefaults standardUserDefaults]removeObjectForKey:@"mliushui"];
[[NSUserDefaults standardUserDefaults]setObject:@"1" forKey:@"mliushui"];
temp = 1;
}
++temp;
[[NSUserDefaults standardUserDefaults]removeObjectForKey:@"mliushui"];
[[NSUserDefaults standardUserDefaults]setObject:[NSString stringWithFormat:@"%d",temp] forKey:@"mliushui"];
NSLog(@"======================================%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"mliushui"]);
在数据库查找的时候防止查找到空的,应该这样。
NSString *mliushui=[NSString stringWithUTF8String:(const char *) sqlite3_column_text(stmt, 5) == nil ? "" : (const char *) sqlite3_column_text(stmt, 5)];
导入数据库的时候应该导入libsqlite3.dylib.
md5加密的方法。
+ (NSString *)md5Digest:(NSString *)str
{
const char *cStr = [str UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5( cStr, strlen(cStr), result);
return [[NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",result[0], result[1], result[2], result[3], result[4], result[5],result[6], result[7],result[8], result[9], result[10], result[11], result[12],
result[13], result[14],result[15]] uppercaseString];
}
//判断程序是否为第一次运行。
if (![[NSUserDefaults standardUserDefaults]boolForKey:@"everLaunch"]) {
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"everLaunch"];
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"firstLaunch"];
}
else{
[[NSUserDefaults standardUserDefaults]setBool:NO forKey:@"firstLaunch"];
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
NSLog(@"第一次运行");
[[NSUserDefaults standardUserDefaults]setObject:@"1" forKey:@"mliushui"];
SetViewController *firstVC=[[SetViewController alloc]init];
self.window.rootViewController=firstVC;
[firstVC release];
}
else{
NSLog(@"不是第一次运行");
MainViewController *mainVc = [MainViewController mainVc];
mainVc.idText = [[NSUserDefaults standardUserDefaults]objectForKey:@"storeId"];
mainVc.imputChese = [[NSUserDefaults standardUserDefaults]objectForKey:@"chese"];
self.window.backgroundColor = [UIColor lightGrayColor];
self.window.rootViewController = mainVc;
//[shouYeVC release];
}
NSString *match =@"^[1-9][0-9]{0,4}$";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
if(![predicate evaluateWithObject:_moneyField.text] || [_moneyField.text intValue] >= 65535){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"请输入小于65535的正整数" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert show];
[alert release];
return;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[_moneyField resignFirstResponder];
[_mchuo resignFirstResponder];
[UIView animateWithDuration:0.6 animations:^{
CGRect rect = self.view.frame;
rect.origin.y = 20;
self.view.frame =rect;
}];
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
if ([textField isEqual:_mchuo]) {//////
NSLog(@"sdgfsg");
[UIView animateWithDuration:0.6 animations:^{
CGRect rect = self.view.frame;
rect.origin.y = -220;
self.view.frame =rect;
}];
}else{
_nextBtn.hidden = YES;
_qrImg.image = nil;
_chese.hidden = YES;
}
return YES;
}
NSString *match =@"^[0-9]{1}|(\\.)$";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
if(![predicate evaluateWithObject:self.mchuo.text]){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"请输入0到9之间的数字或者 . " delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert show];
[alert release];
return;
}