实战知识点和错误
知识点:
1.
//字体居中
cell.textLabel.textAlignment = UITextAlignmentCenter;
设置字体
cell.textLabel.font = [UIFontsystemFontOfSize:16];
//切换场景
presentModalViewController
对应
[self dismissModalViewControllerAnimated:YES]
pushViewController
对应
[self.navigationControllerpopViewControllerAnimated:YES];
//位置大小
UIImageView:
backgroundViewMid.frame.size.height 是这个UIImageView的高度
backgroundViewMid.frame.size.width 是这个UIImageView的宽度
backgroundViewMid.frame.origin.x 是这个UIImageView的x位置
backgroundViewMid.frame.origin.y 是这个UIImageView的y位置
2.
UITableView: 新建cell.textLabel.text不能控制其长度 需要新建一个UILabel
UILabel: 在xib中建立了UILabel 设定了frame的位置 在程序中没法再设置 必须自己手动建立一个UILabel
3.
tableviewcell不可选中(但是要是上面放按钮也不能点)
cell.userInteractionEnabled = NO;
//cell设置为不可选 放按钮可点
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//选中后的背景框颜色即刻消失
[tableView deselectRowAtIndexPath:indexPath animated:YES];
4.写数据
//获得所有的学科
+(NSArray*) allSubjects
{
NSMutableArray* subjectArray = [NSMutableArrayarray];
NSMutableDictionary* subjectDict = nil;
subjectDict = [NSMutableDictionary dictionary];
[subjectDict setObject:@"自然学科" forKey:@"name"];
[subjectDict setObject:@"1" forKey:@"id"];
[subjectArray addObject:subjectDict];
subjectDict = [NSMutableDictionary dictionary];
[subjectDict setObject:@"人文社会" forKey:@"name"];
[subjectDict setObject:@"2" forKey:@"id"];
[subjectArray addObject:subjectDict];
subjectDict = [NSMutableDictionary dictionary];
[subjectDict setObject:@"工程设计" forKey:@"name"];
[subjectDict setObject:@"3" forKey:@"id"];
[subjectArray addObject:subjectDict];
subjectDict = [NSMutableDictionary dictionary];
[subjectDict setObject:@"农业医药" forKey:@"name"];
[subjectDict setObject:@"4" forKey:@"id"];
[subjectArray addObject:subjectDict];
return subjectArray;
}
//获得更新包
-(NSMutableDictionary*) allEntryData
{
NSMutableDictionary* subjectDict = [NSMutableDictionarydictionary];
NSMutableArray* subjectArray = nil;
subjectArray = [[[NSMutableArray alloc] init] autorelease];
[subjectArray addObject:@"2012年8月30日天文学更新包"];
[subjectDict setObject:subjectArray forKey:@"A"];
subjectArray = [[[NSMutableArray alloc] init] autorelease];
[subjectArray addObject:@"2012年8月35日人文社会学更新包"];
[subjectDict setObject:subjectArray forKey:@"B"];
return subjectDict;
}
5.
设置UIButton上字体的颜色,不是用:
[payWayButton.titleLabelsetTextColor:[UIColorblackColor]];
而是用:
[payWayButtonsetTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
6.
int iSection = 0;
iSection += 1;
subjectArray = [[[NSMutableArray alloc] init] autorelease];
[subjectArray addObject:@"2012年8月30日天文学更新包"];
[subjectDict setObject:subjectArray forKey:[NSString stringWithFormat:[NSString stringWithFormat:@"%d", iSection], nil]];
7.tableview自己画线对齐要注意分割线不能去掉只能把颜色清空
不能用 这个是去掉tableview自己画线 就不会自动对齐
gradeTwoTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
要用 这个只是去掉分割线颜色还会自动对齐
gradeTwoTableView.separatorColor = [UIColorclearColor];
7.post请求
// NSString *post = [NSString stringWithFormat:nil, 4, opinionTextView.text];
// NSData *postData=[post dataUsingEncoding:NSUTF8StringEncoding];
// NSMutableURLRequest *connectionRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:nil]];
// [connectionRequest setHTTPMethod:@"POST"];
// [connectionRequest setTimeoutInterval:100.0];
// [connectionRequest setCachePolicy:NSURLRequestUseProtocolCachePolicy];
// [connectionRequest setHTTPBody:postData];
//
// //输出数据
// NSData *data=[NSURLConnection sendSynchronousRequest:connectionRequest returningResponse:nil error:nil];
// NSString *stringdata=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// NSLog(@"%@", stringdata);
NSString *post = @"name=admin&password=123456";
NSData *postData=[post dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *connectionRequest = [NSMutableURLRequest
requestWithURL:[NSURL URLWithString:@"http://127.0.0.1/test/test.php"]];
[connectionRequest setHTTPMethod:@"POST"];
[connectionRequest setTimeoutInterval:100.0];
[connectionRequest setCachePolicy:NSURLRequestUseProtocolCachePolicy];
[connectionRequest setHTTPBody:postData];
NSData *data=[NSURLConnectionsendSynchronousRequest:connectionRequest returningResponse:nilerror:nil];
NSString *stringdata=[[NSStringalloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"~~~~~%@~~~~",stringdata);
//去掉空格
NSString* isRightWord = [ageTextField.textstringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceCharacterSet] ];
if (isRightWord == nil || [@"" isEqualToString:isRightWord])
{
UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:@""message:@"年龄不能为空!" delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil, nil];
[alert show];
[alert release];
return;
}
1、判断用户名,在2-16位
-(BOOL)CheckInput:(NSString *)_text
{
NSString *Regex = @"^\\w{2,16}$";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", Regex];
return [emailTest evaluateWithObject:_text];
}
2、判断手机号码,1开头的十一位数字
-(BOOL)CheckInput:(NSString *)_text
{
NSString *Regex = @"1\\d{10}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", Regex];
return [emailTest evaluateWithObject:_text];
}
3、判断邮箱
-(BOOL)CheckInput:(NSString *)_text
{
NSString *Regex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", Regex];
return [emailTest evaluateWithObject:_text];
}
4、判断密码,6-16位
-(BOOL)CheckInput:(NSString *)_text
{
NSString *Regex = @"\\w{6,16}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", Regex];
return [emailTest evaluateWithObject:_text];
}
5、判断是否为整型
- (BOOL)isPureInt:(NSString *)string{
NSScanner* scan = [NSScanner scannerWithString:string];
int val;
return [scan scanInt:&val] && [scan isAtEnd];
}
6、判断是否为浮点型
- (BOOL)isPureFloat:(NSString *)string{
NSScanner* scan = [NSScanner scannerWithString:string];
float val;
return [scan scanFloat:&val] && [scan isAtEnd];
1。
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_EGORefreshTableHeaderView", referenced from:
objc-class-ref in CategoryGradeTwo.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
需要加framework 如果还有错误 就点击 报错的类 再把右上角 target membership里的勾打上
2.
format string is not a string literal (potentially insecure)
加个nil既可解决
[selfhudLabelText:[NSStringstringWithFormat:sError.error,nil]];
3.
xcode 升级到了 4.5 之后 只要往xib上面拖放控件 就会报错,
解决方法, 选中当前的 xib文件,
再右边的 inspector 一栏 将 interface builder document 下的 use autolayout 复选框去掉就可以了
VIA:http://www.lazyid.com/2012/07/04/could-not-instantiate-class-named-nslayoutconstraint/comment-page-1/

浙公网安备 33010602011771号