1:设置有间距的表格行(UITableViewStyleGrouped)
1.设置section的数目,即是你有多少个cell - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 3; // in your case, there are 3 cells} 2.对于每个section返回一个cell - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 1;} 3.设置cell之间headerview的高度 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 10.; // you can have your own choice, of course} 4.设置headerview的颜色 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ UIView *headerView = [[UIView alloc] init]; headerView.backgroundColor = [UIColor clearColor]; return headerView;} 注意:需要使用 indexpath.section 来获得index,而不是用 indexpath.row cell.textLabel.text=[NSString stringWithFormat:@"%@",[array objectAtIndex:indexPath.section]];
实例:
创建表格代码: if (!_myTableView) { _myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.customheadView.frame), Main_Screen_Width, Main_Screen_Height-204) style:UITableViewStyleGrouped]; _myTableView.backgroundColor = [UIColor clearColor]; _myTableView.showsVerticalScrollIndicator = NO; _myTableView.showsHorizontalScrollIndicator=NO; _myTableView.dataSource = self; _myTableView.delegate = self; _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone; [_myTableView registerClass:[BLSReplenishmentCell class] forCellReuseIdentifier:BLSReplenishmentViewController_CellIdentifier]; [self.view addSubview:_myTableView]; } 其它方法: #pragma mark UITableViewDataSource和UITableViewDelegate - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 10; } //若设置为0 效果会达不到想要的 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 1; } -(NSInteger)numberOfSectionsInTableView:(nonnull UITableView *)tableView { return self.recordDatalist.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ BLSReplenishmentCell *cell = [tableView dequeueReusableCellWithIdentifier:BLSReplenishmentViewController_CellIdentifier forIndexPath:indexPath]; cell.cur_Replenishment = [self.recordDatalist objectAtIndex:indexPath.section]; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return [BLSReplenishmentCell cellHeight]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; }
2:Xcode7 使用NSURLSession发送HTTP请求报错
报错内容:控制台打印:Application Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app‘s Info.plist file.
解决办法:修改info.plist文件
3:对UITextField内容实时监听长度和内容
//第一步,对组件增加监听器 [textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; ... //第二步,实现回调函数 - (void) textFieldDidChange:(id) sender { UITextField *_field = (UITextField *)sender; NSLog(@"%@,%d",[_field text],_field.text.length); }
4:真机调试报Please verify that your device‘s clock is properly set, and that your signing certificate is not expired
注意:在Tagers-build Settings--Code signing--Code Signing Identity 中的Any IOS SDK记得选对证书
5:给UIAlertView增加UITextView,并获得它的值
MjyAlterView.h #import <UIKit/UIKit.h> #import "UIPlaceHolderTextView.h" typedef void(^AlertViewBlock)(NSInteger index,NSString *textValue); @interface MjyAlterView : UIAlertView @property (nonatomic,copy)AlertViewBlock block; - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles clickButton:(AlertViewBlock)block; @end MjyAlterView.m #import "MjyAlterView.h" @interface MjyAlterView()<UIAlertViewDelegate,UITextViewDelegate> @property(copy,nonatomic)NSString *content; @end @implementation MjyAlterView - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles clickButton:(AlertViewBlock)block{ self = [super initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles, nil]; self.backgroundColor = [UIColor whiteColor]; UIPlaceHolderTextView *textView = [[UIPlaceHolderTextView alloc]init]; textView.delegate=self; textView.font=[UIFont systemFontOfSize:15]; textView.placeholder=@"输入内容"; textView.layer.borderColor=[UIColor grayColor].CGColor; textView.layer.borderWidth=0.5; // if (SYSTEM_VERSION_LESS_THAN(@"7.0"))//当系统为IOS7时 // { // [testAlert addSubview: textView]; // } // else//当系统为IOS8 // { [self setValue: textView forKey:@"accessoryView"]; // } if (self) { _block = block; } return self; } #pragma mark UIAlertViewDelegate - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (_block != nil) { _block(buttonIndex,self.content); } } #pragma mark UITextViewDelegate - (void)textViewDidChange:(UITextView *)textView{ self.content=textView.text; } @end
调用: __weak ViewController *weakThis = self; AlertViewBlock block = ^(NSInteger index,NSString *content) { __strong ViewController *strongThis = weakThis; if (index == 1) { NSLog(@"确定,--%@",content); }else if (index == 0){ strongThis.showLabel.text = @"取消"; } }; MjyAlterView *alterView = [[MjyAlterView alloc] initWithTitle:@""message:@""cancelButtonTitle:nil otherButtonTitles:@"确定" clickButton:block]; [alterView show];
时间: 2024-11-05 15:57:35