国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

IOS開發基礎知識--碎片22

2019-11-14 18:15:33
字體:
來源:轉載
供稿:網友

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.rowcell.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;@endMjyAlterView.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];

 6:iOS UILabel顯示HTML文本(IOS7以上)

NSString * htmlString = @"<html><body> Some html string /n <font size=/"13/" color=/"red/">This is some text!</font> </body></html>";  NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];  UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds];  myLabel.attributedText = attrStr;  [self.view addSubview:myLabel]; 

運用實例(自動高度)

        if (self.contentLabel==nil) {            self.contentLabel=[[UILabel alloc]init];            self.contentLabel.textColor=COLOR_Word_GRAY_1;            self.contentLabel.font=[UIFont systemFontOfSize:14];            self.contentLabel.numberOfLines=0;            [self.contentLabel sizeToFit];            [self.contentView addSubview:self.contentLabel];            [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {                make.left.mas_equalTo(self.contentView.left).with.offset(leftSpace);                make.right.mas_equalTo(self.contentView.right).with.offset(-leftSpace);                make.top.mas_equalTo(self.lineView.bottom).with.offset(topSpace);            }];        }賦值:        NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[model.content dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];        self.contentLabel.attributedText = attrStr;

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 湖口县| 平安县| 莎车县| 芮城县| 来安县| 图木舒克市| 育儿| 和静县| 高雄市| 盐城市| 郎溪县| 包头市| 乾安县| 仪征市| 岐山县| 宁陵县| 廉江市| 双城市| 开鲁县| 榕江县| 江源县| 阿鲁科尔沁旗| 平和县| 土默特左旗| 芷江| 渑池县| 灵武市| 离岛区| 塔河县| 临潭县| 尉犁县| 五家渠市| 西吉县| 翁源县| 柏乡县| 小金县| 和龙市| 武城县| 六盘水市| 五台县| 禄劝|