国庆节了,这几天一直没写,有一项任务要在国庆节前完成,所以没什么时间,知识倒是有新增加,下午就坐火车回家了,所以现在赶紧写写吧。
话说时间过的真快 一下子就国庆了,感觉准备都没有 今天下午就要回家了。
push界面出现空白,并且会卡一下才过去
在这我的原因是 因为要push的界面的xib的问题,或者是push前加载xib的问题。
-(void)ItemButtonAction:(id)sender{
UIButton *t_btn = (UIButton *)sender;
if (t_btn.tag == 0 ) {
KQViewController *kq_vc = [[KQViewController alloc] initWithNibName:@"KQViewController" bundle:nil];
[self.navigationController pushViewController:kq_vc animated:YES];
}else if (t_btn.tag == 8 || t_btn.tag == 7 || t_btn.tag == 5|| t_btn.tag == 2) {
Class clazz = NSClassFromString([self.controllerArr objectAtIndex:t_btn.tag]);
id viewController = [[clazz alloc] init];
if (viewController) {
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = YES; self.navigationController.interactivePopGestureRecognizer.delegate = nil; }
[self.navigationController pushViewController:viewController animated:YES];
}
}
else{
[XCCommonUtility QQTShowAlertMsg:@"功能研发中"];
}
}
上拉刷新、下拉刷新
由于要实现上拉刷新实现动态加载。去code4找了MJ的demo,当初学习ios,就是他的视频给了我非常大的帮助,集成过程非常简单。其中要注意的就是,我碰到的问题就是 3.5-inch上拉刷新的时候,上拉的字幕位置不对。仔细找乐原因。 原demo并没有xib画出tableView,在我的工程中,是画了个tableView,我重新用代码创建,然后区分4、3.5的分别大小,这样字幕就对了。
在
点击第几个则刷新表格,√ 就在第几个。
记住 当第二个界面是修改 例如 号码的时候,你上传的时候 姓名同样要继续转码 我就没考虑到这点
要懂是什么意思。
if (IS_4_INCH) {
_tableView.frame = CGRectMake(0, 0, 320, 505);
}else{
_tableView.frame = CGRectMake(0, 0, 320, 420);
}
cell中分别打钩
要在indexPath.row中分别单选 打钩。
if(indexPath.section == 2){
static NSString *CellIdentifier = @"ThreeCell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[BorderProperties cellIndexPath:indexPath addSub:cell Frame:CGRectMake(0,49.5, ScreenWidth,1)];
UIImageView *selectedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 18.f, 18.f)];
[selectedImageView setCenter:CGPointMake(300, 20)];
selectedImageView.tag = 16;
[cell.contentView addSubview:selectedImageView];
[cell.textLabel setHighlightedTextColor:[UIColor colorWithWhite:0.530 alpha:1.000]];
[cell.textLabel setTextColor:[UIColor blackColor]];
[cell.textLabel setFont:[UIFont fontWithName:@"STHeitiSC-Medium" size:16]];
}
NSArray * item = @[@"一次",@"每周",@"每月"];
[cell.textLabel setText:[item objectAtIndex:indexPath.row]];
UIImageView *selectedImageView = (UIImageView *)[cell.contentView viewWithTag:16];
if (self.selectRow == indexPath.row) {
[selectedImageView setImage:[UIImage imageNamed:@"icon_selected.png"]];
}else{
[selectedImageView setImage:nil];
}
return cell;
}
在
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
if (indexPath.section == 2) {
switch (indexPath.row) {
case 0:{
self.selectRow = indexPath.row;
[self.tableView reloadData];
break;
}
case 1:{
self.selectRow = indexPath.row;
[self.tableView reloadData];
break;
}
case 2:{
self.selectRow = indexPath.row;
[self.tableView reloadData];
break;
}
default:
break;
}
}
点击第几个则刷新表格,√ 就在第几个。
在textView中放入 输入就能消失的提示标签
大概的思路如下代码
-(void)textViewDidChange:(UITextView *)textView
{
if (textView.text.length == 0) {
_dec.text = @"日程备注";
}else{
_dec.text = @"";
}
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
if (textView.text.length == 0) {
_dec.text = @"";
}
return YES;
}
下面几行代码好像可以不用
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if ([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}
头部、尾部的高度、视图
按照目前我的理解,一直没去百度。
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
设置了上面那个,假如不要尾部,则下面的也要设置,不然的话 尾部也有默认的高度,不要想这个高度,设为0.01f即可,不能设置为0,否则又是默认的高度。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 2) {
UIView *t_view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 0)];
t_view.backgroundColor = [UIColor clearColor];
UILabel *t_label = [[UILabel alloc] initWithFrame:CGRectMake(5, 12, 150, 20)];
t_label.text = @"周期设置";
[t_label setBackgroundColor:[UIColor clearColor]];
[t_label setFont:[UIFont fontWithName:@"STHeitiSC-Light" size:14]];
[t_label setTextColor:[UIColor colorWithRed:153.0f/255.0f green:153.0f/255.0f blue:153.0f/255.0f alpha:1]];
[t_label setTextAlignment:kTextAlignmentLeft];
[t_view addSubview:t_label];
return t_view;
}else{
return nil;
}
}
密码、中文转码、判断固定电话
这几个百度非常容易找到,不过既然我碰到了 就写一写吧。。
密码采取 GTMBase64加密。网上应该有相应的库。
NSData *temp_oldData = [_oldKey.text dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *b64_oldPws = [[NSString alloc] initWithData:[GTMBase64 encodeData:temp_oldData] encoding:NSUTF8StringEncoding];
NSString *t_Freason = [self.textView.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *dele = [weakSelf.textView.text stringByReplacingOccurrencesOfString:@"-" withString:@""];
NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", PHS];
if ([XCStringUtility isValidateMobile:weakSelf.textView.text] || ([regextestct evaluateWithObject:dele])){
}
/*手机号码验证 MODIFIED BY HELENSONG*/
+ (BOOL)isValidateMobile:(NSString *)mobile{
//手机号以13, 15,18开头,八个 \d 数字字符
NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
// NSLog(@"phoneTest is %@",phoneTest);
return [phoneTest evaluateWithObject:mobile];
}
记住 视图之间的传递数据,单纯的数组跟模型是有区别的
写一个我自己写的,发现挺好的传递信息实现 利用数组,下个界面中可以修改资料,上传服务器 功能的代码
EditProfileVC *t_vc = [[EditProfileVC alloc] initWithNibName:@"EditProfileVC" bundle:nil];
[t_vc setNavText:_lableArry[indexPath.row]];
t_vc.info = [NSMutableArray arrayWithArray:self.infoArry];
t_vc.index = indexPath.row;
-(void)viewWillAppear:(BOOL)animated{
_textView.text = self.info[_index];
if ([_textView.text isEqualToString:@""]) {
_placLabel.text = [NSString localizedStringWithFormat:@"请输入%@",self.navText];
}
}
记住 当第二个界面是修改 例如 号码的时候,你上传的时候 姓名同样要继续转码 我就没考虑到这点
if ([self.navText isEqual:@"姓名"]) {
NSString *t_Freason = [self.textView.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[self.info replaceObjectAtIndex:self.index withObject:t_Freason];
}else{
NSString *t_Freason = [self.info[0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[self.info replaceObjectAtIndex:0 withObject:t_Freason];
[self.info replaceObjectAtIndex:self.index withObject:self.textView.text];
}
base视图的UINavigation
我项目中 基本所有视图都是继承
@interface
HomeVC :
BaseViewController
但是
BaseViewController本身并不是
UINavigationController 。
@interface
BaseViewController :
UIViewController
所以是怎么让 视图有 Navigation的效果。
HomeVC *t_vc = [[HomeVC alloc] initWithNibName:@"HomeVC" bundle:nil];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:t_vc];
[self presentViewController:nc animated:YES completion:nil];
另:有的在AppDelegate中写到
LoginVC *t_vc = [[LoginVC alloc] initWithNibName:@"LoginVC" bundle:nil];
self.nc = [[UINavigationController alloc] initWithRootViewController:t_vc];
self.window.rootViewController = t_vc;
要懂是什么意思。