-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.xml
147 lines (103 loc) · 38 KB
/
search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title></title>
<url>%2F2024%2F03%2F31%2FiOS%2FiOS%E5%BC%80%E5%8F%91%E7%BB%84%E4%BB%B6%E5%8C%96%2F</url>
<content type="text"><![CDATA[1234title: iOS组件化date: 2024-03-31tags:- iOS 1. 首先创建自己的framework1pod lib create DHFramework 跟随提示选择相应的内容就好了 将自己的代码放到Classes目录下 2. 创建framework的仓库创建一个代码仓库, clone下来后将.git替换掉DHFramework下的.git文件 新建tag1.0.0 打开podspec文件,修改版本号为1.0.0及仓库地址,并推送到远端 3. 创建数据源仓库新建一个代码仓库DHRepo,在文件夹下我们可以创建好自己的库名及版本号,将DHFramework下的podspec文件拷贝到DHRepo文件夹里,并推送到远端 4. 使用在podfile文件里指定数据源可直接使用自己的库了 1source '[email protected]:DajuanM/DHRepo.git' 1pod 'DHFramework']]></content>
</entry>
<entry>
<title><![CDATA[将自己的库上传到cocopods]]></title>
<url>%2F2017%2F07%2F10%2FiOS%2F%E5%B0%86%E8%87%AA%E5%B7%B1%E7%9A%84%E5%BA%93%E4%B8%8A%E4%BC%A0%E5%88%B0cocopods%2F</url>
<content type="text"><![CDATA[升级版本 12$sudo gem install cocoa podspod setup 注册 1pod trunk register [email protected] 'Aiden' --verbose 注册完成可以查看信息 1pod trunk me 创建.spec文件 1pod spec create DHCalendarView 打开DHCalendarView.podspec填写信息 123456789101112131415Pod::Spec.new do |s|s.name = "DHCalendarView"s.version = "1.0.4"s.summary = "日历"s.description = <<-DESC好用的日历DESCs.homepage = "https://github.com/DajuanM/DHCalendarView"s.license = "MIT"s.author = { "Aiden" => "[email protected]" }s.source = { :git => "https://github.com/DajuanM/DHCalendarView.git", :tag => "#{s.version}" }s.source_files = "DHCalendarView","DHCalendarView/**/*.{h,m}"s.requires_arc = trues.ios.deployment_target = '8.0'end 所有的符号必须要是英文符号,不然会报错 这中间可能会报一些错误,根据提示解决就好了 忽略警告 1pod lib lint --allow-warnings 验证文件是否编写正确 1pod lib lint DHCalendarView.podspec 创建tag 12git tag '1.0.4'git push --tags 把编写的文件告诉cocopods 1pod trunk push DHCalendarView.podspec 出现以下信息就算成功了 错误: 解决方法 1pod trunk push DHCalendarView.podspec --allow-warnings]]></content>
</entry>
<entry>
<title><![CDATA[React Native环境搭建]]></title>
<url>%2F2017%2F06%2F15%2FReact-Native%2FReact-Native%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA%2F</url>
<content type="text"><![CDATA[安装Node.js官网:https://nodejs.org/en/ 安装Homebrewruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 安装watchmanbrew install watchman 安装flowbrew install flow 安装nvmbrew install nvm 安装React Native命令行工具npm install -g react-native-cli 创建React Native项目 cd 项目存放文件夹 react-native init 项目名 react-native run-ios / react-native run-andriod 代码提示https://github.com/virtoolswebplayer/ReactNative-LiveTemplate]]></content>
</entry>
<entry>
<title><![CDATA[LeetCode-485. Max Consecutive Ones]]></title>
<url>%2F2017%2F06%2F15%2F%E7%AE%97%E6%B3%95%2FLeetCode-485-Max-Consecutive-Ones%2F</url>
<content type="text"><![CDATA[Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: 123Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutive 1s.The maximum number of consecutive 1s is 3. Note:** The input array will only contain 0 and 1. The length of input array is a positive integer and will not exceed 10,000 Subscribe to see which companies asked this question. 12345678910111213141516func findMaxConsecutiveOnes(_ nums: [Int]) -> Int { var count = 0,maxCount = 0 var i = 0 while i < nums.count { while i < nums.count && nums[i] == 1{ count += 1 i += 1 } if count > maxCount { maxCount = count } count = 0 i += 1 } return maxCount}]]></content>
</entry>
<entry>
<title><![CDATA[LeetCode-561 Array Partition I]]></title>
<url>%2F2017%2F06%2F15%2F%E7%AE%97%E6%B3%95%2FLeetCode-561-Array-Partition-I%2F</url>
<content type="text"><![CDATA[题目Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possible.Example 1:Input: [1,4,3,2]Output: 4Explanation: n is 2, and the maximum sum of pairs is 4 = min(1, 2) + min(3, 4). Note:n is a positive integer, which is in the range of [1, 10000].All the integers in the array will be in the range of [-10000, 10000]. Subscribe to see which companies asked this question. 代码1234567891011121314func arrayPairSum(_ nums: [Int]) -> Int { guard nums.count % 2 == 0 else { return 0 } var arr = nums arr.sort() var sum = 0 for i in 0..<arr.count { if i % 2 == 0 { sum += arr[i] } } return sum}]]></content>
</entry>
<entry>
<title><![CDATA[LeetCode-566 Reshape the Matrix]]></title>
<url>%2F2017%2F06%2F15%2F%E7%AE%97%E6%B3%95%2FLeetCode-566-Reshape-the-Matrix%2F</url>
<content type="text"><![CDATA[题目In MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data. You’re given a matrix represented by a two-dimensional array, and two positive integers r and c representing the row number and column number of the wanted reshaped matrix, respectively. The reshaped matrix need to be filled with all the elements of the original matrix in the same row-traversing order as they were. If the ‘reshape’ operation with given parameters is possible and legal, output the new reshaped matrix; Otherwise, output the original matrix. Example 1:Input: nums = [[1,2], [3,4]]r = 1, c = 4Output: [[1,2,3,4]]Explanation:The row-traversing of nums is [1,2,3,4]. The new reshaped matrix is a 1 * 4 matrix, fill it row by row by using the previous list. Example 2:Input: nums = [[1,2], [3,4]]r = 2, c = 4Output: [[1,2], [3,4]]Explanation:There is no way to reshape a 2 2 matrix to a 2 4 matrix. So output the original matrix. Note:The height and width of the given matrix is in range [1, 100].The given r and c are all positive. Subscribe to see which companies asked this question. 代码123456789101112131415func matrixReshape(_ nums: [[Int]], _ r: Int, _ c: Int) -> [[Int]] { var tmp: [Int] = nums.flatMap{$0} guard tmp.count % (r * c) == 0 else { return nums } var arr: [[Int]] = [] for i in 0..<r { var t: [Int] = [] for j in 0..<c { t.append(tmp[i*c+j]) } arr.append(t) } return arr}]]></content>
</entry>
<entry>
<title><![CDATA[LeetCode-581. Shortest Unsorted Continuous Subarray]]></title>
<url>%2F2017%2F06%2F15%2F%E7%AE%97%E6%B3%95%2FLeetCode-581-Shortest-Unsorted-Continuous-Subarray%2F</url>
<content type="text"><![CDATA[题目Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.You need to find the shortest such subarray and output its length.Example 1:Input: [2, 6, 4, 8, 10, 9, 15]Output: 5Explanation: You need to sort [6, 4, 8, 10, 9] in ascending order to make the whole array sorted in ascending order. Note:Then length of the input array is in range [1, 10,000].The input array may contain duplicates, so ascending order here means <=. Subscribe to see which companies asked this question. 代码1234567891011121314func findUnsortedSubarray(_ nums: [Int]) -> Int { var arr = nums arr.sort() var start = 0 var end = nums.count - 1 while start < nums.count && nums[start] == arr[start] { start += 1 } while end > start && nums[end] == arr[end] { end -= 1 } return end - start + 1}]]></content>
</entry>
<entry>
<title><![CDATA[LeetCode-605. Can Place Flowers]]></title>
<url>%2F2017%2F06%2F15%2F%E7%AE%97%E6%B3%95%2FLeetCode-605-Can-Place-Flowers%2F</url>
<content type="text"><![CDATA[题目Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die.Given a flowerbed (represented as an array containing 0 and 1, where 0 means empty and 1 means not empty), and a number n, return if n new flowers can be planted in it without violating the no-adjacent-flowers rule.Example 1:Input: flowerbed = [1,0,0,0,1], n = 1Output: True Example 2:Input: flowerbed = [1,0,0,0,1], n = 2Output: False Note:The input array won’t violate no-adjacent-flowers rule.The input array size is in the range of [1, 20000].n is a non-negative integer which won’t exceed the input array size. Subscribe to see which companies asked this question. 代码1234567891011121314func canPlaceFlowers(_ flowerbed: [Int], _ n: Int) -> Bool { var count: Int = 0 var arr = flowerbed for i in 0..<arr.count { if (arr[i] == 0 && (i == 0 || arr[i - 1] == 0) && (i == arr.count - 1 || arr[i + 1] == 0)) { arr[i] = 1 count += 1 } if count >= n { return true } } return false }]]></content>
</entry>
<entry>
<title><![CDATA[UITableView长按拖动排序(支持不同行高间交换)]]></title>
<url>%2F2017%2F06%2F09%2FiOS%2FUITableView%E9%95%BF%E6%8C%89%E6%8B%96%E5%8A%A8%E6%8E%92%E5%BA%8F%EF%BC%88%E6%94%AF%E6%8C%81%E4%B8%8D%E5%90%8C%E8%A1%8C%E9%AB%98%E9%97%B4%E4%BA%A4%E6%8D%A2%EF%BC%89%2F</url>
<content type="text"><![CDATA[效果图: github下载地址:DHDragableCellTableView 使用将tableView继承与DHDragableCellTableView并遵循协议DHDragableCellTableViewDataSource,DHDragableCellTableViewDelegate 123456789#pragma mark - DHDragableCellTableViewDataSource- (NSArray *)dataSourceArrayInTableView:(DHDragableCellTableView *)tableView{ return self.dataSource.copy;//数据源}- (void)tableView:(DHDragableCellTableView *)tableView newDataSourceArrayAfterMove:(NSArray *)newDataSourceArray{ self.dataSource = newDataSourceArray.mutableCopy;//返回的数据源 [self.tableView reloadData];} 实现:大概思路,为UITableView添加长按手势,长按后给选择的cell截图并隐藏选择的cell,让截图跟随手势移动 添加手势 123456789/** 添加手势 */- (void)dh_addGesture{ _gesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(dh_processGesture:)]; _gesture.minimumPressDuration = _gestureMinimumPressDuration; [self addGestureRecognizer:_gesture];} 监听手势状态 12345678910111213141516171819202122232425- (void)dh_processGesture:(UILongPressGestureRecognizer *)gesture{ switch (gesture.state) { case UIGestureRecognizerStateBegan: { [self dh_gestureBegan:gesture]; } break; case UIGestureRecognizerStateChanged: { if (!_canEdgeScroll) { [self dh_gestureChanged:gesture]; } } break; case UIGestureRecognizerStateEnded: case UIGestureRecognizerStateCancelled: { [self dh_gestureEndedOrCancelled:gesture]; } break; default: break; }} 开始拖动 123456789101112131415161718192021222324252627282930313233343536373839404142- (void)dh_gestureBegan:(UILongPressGestureRecognizer *)gesture{ CGPoint point = [gesture locationInView:gesture.view]; self.lastPoint = point; NSIndexPath *selectedIndexPath = [self indexPathForRowAtPoint:point]; if (!selectedIndexPath) { return; } if (self.delegate && [self.delegate respondsToSelector:@selector(tableView:willMoveCellAtIndexPath:)]) { [self.delegate tableView:self willMoveCellAtIndexPath:selectedIndexPath]; } if (_canEdgeScroll) { //开启边缘滚动 [self dh_startEdgeScroll]; } //每次移动开始获取一次数据源 if (self.dataSource && [self.dataSource respondsToSelector:@selector(dataSourceArrayInTableView:)]) { _tempDataSource = [self.dataSource dataSourceArrayInTableView:self].mutableCopy; } _selectedIndexPath = selectedIndexPath; UITableViewCell *cell = [self cellForRowAtIndexPath:selectedIndexPath]; _tempView = [self dh_snapshotViewWithInputView:cell]; if (_drawMovalbeCellBlock) { //将_tempView通过block让使用者自定义 _drawMovalbeCellBlock(_tempView); }else { //配置默认样式 _tempView.layer.shadowColor = [UIColor grayColor].CGColor; _tempView.layer.masksToBounds = NO; _tempView.layer.cornerRadius = 0; _tempView.layer.shadowOffset = CGSizeMake(-5, 0); _tempView.layer.shadowOpacity = 0.4; _tempView.layer.shadowRadius = 5; } _tempView.frame = cell.frame; [self addSubview:_tempView]; //隐藏cell cell.hidden = YES; [UIView animateWithDuration:kDH_DragableCellAnimationTime animations:^{ _tempView.center = CGPointMake(_tempView.center.x, point.y); }];} 拖动 这里的_toBottom是int类型用来判断手势是向哪一个方向拖动,然后根据拖动的cell跟要交换的cell的中心点进行比较,判断是否交换 1234567891011121314151617181920212223242526272829- (void)dh_gestureChanged:(UILongPressGestureRecognizer *)gesture{ CGPoint point = [gesture locationInView:gesture.view]; //判断拖动的方向 if (point.y - self.lastPoint.y > 0) { _toBottom = 1;//向下拖 }else if(point.y - self.lastPoint.y < 0){ _toBottom = -1;//向上拖 }else{ _toBottom = 0; } self.lastPoint = point; NSIndexPath *currentIndexPath = [self indexPathForRowAtPoint:point]; if (currentIndexPath && ![_selectedIndexPath isEqual:currentIndexPath]) { UITableViewCell *cell = [self cellForRowAtIndexPath:_selectedIndexPath]; UITableViewCell *cell1 = [self cellForRowAtIndexPath:currentIndexPath]; //将拖动的cell跟要交换的cell的centerY进行比较 if ((_toBottom == 1 && (point.y+cell.frame.size.height/2) >= CGRectGetMaxY(cell1.frame) && (CGRectGetMaxY(cell1.frame) >= CGRectGetMaxY(cell.frame))) || ((_toBottom == -1 && (point.y-cell.frame.size.height/2) <= CGRectGetMinY(cell1.frame)) && (CGRectGetMinY(cell1.frame) <= CGRectGetMinY(cell.frame)))) { //交换数据源和cell [self dh_updateDataSourceAndCellFromIndexPath:_selectedIndexPath toIndexPath:currentIndexPath]; if (self.delegate && [self.delegate respondsToSelector:@selector(tableView:didMoveCellFromIndexPath:toIndexPath:)]) { [self.delegate tableView:self didMoveCellFromIndexPath:_selectedIndexPath toIndexPath:currentIndexPath]; } _selectedIndexPath = currentIndexPath; } } //让截图跟随手势 _tempView.center = CGPointMake(_tempView.center.x, point.y);} 交换数据跟cell的位置 为了在不同行高交换时cell不变形,交换后要立刻reloadData,再通过对两个cell截图,用截图来模拟交换的动画 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657/** 交换数据源 跟 cell的位置 */- (void)dh_updateDataSourceAndCellFromIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath{ if ([self numberOfSections] == 1) { //只有一组 [_tempDataSource exchangeObjectAtIndex:fromIndexPath.row withObjectAtIndex:toIndexPath.row]; //交换cell [self moveRowAtIndexPath:fromIndexPath toIndexPath:toIndexPath]; }else { //有多组 id fromData = _tempDataSource[fromIndexPath.section][fromIndexPath.row]; id toData = _tempDataSource[toIndexPath.section][toIndexPath.row]; NSMutableArray *fromArray = [_tempDataSource[fromIndexPath.section] mutableCopy]; NSMutableArray *toArray = [_tempDataSource[toIndexPath.section] mutableCopy]; [fromArray replaceObjectAtIndex:fromIndexPath.row withObject:toData]; [toArray replaceObjectAtIndex:toIndexPath.row withObject:fromData]; [_tempDataSource replaceObjectAtIndex:fromIndexPath.section withObject:fromArray]; [_tempDataSource replaceObjectAtIndex:toIndexPath.section withObject:toArray]; //交换cell [self beginUpdates]; [self moveRowAtIndexPath:fromIndexPath toIndexPath:toIndexPath]; [self moveRowAtIndexPath:toIndexPath toIndexPath:fromIndexPath]; [self endUpdates]; } //交换数据源后reloadData [self reloadData]; //返回交换后的数据源 if (self.dataSource && [self.dataSource respondsToSelector:@selector(tableView:newDataSourceArrayAfterMove:)]) { [self.dataSource tableView:self newDataSourceArrayAfterMove:_tempDataSource.copy]; } //此处用两个cell的截图实现交换的动画 UITableViewCell *cell = [self cellForRowAtIndexPath:fromIndexPath]; cell.hidden = NO; UITableViewCell *cell1 = [self cellForRowAtIndexPath:toIndexPath]; cell1.hidden = YES; UIView *tmpCell = [self dh_snapshotViewWithInputView:cell]; cell.hidden = YES; tmpCell.frame = cell1.frame; if (_toBottom == -1) {//向上 tmpCell.frame = CGRectMake(0, CGRectGetMinY(cell1.frame), cell.frame.size.width, cell.frame.size.height); [self insertSubview:tmpCell belowSubview:_tempView]; }else if (_toBottom == 1) {//向下 tmpCell.frame = CGRectMake(0, CGRectGetMaxY(cell1.frame)-cell.frame.size.height, cell.frame.size.width, cell.frame.size.height); [self insertSubview:tmpCell belowSubview:_tempView]; }else{ } [UIView animateWithDuration:0.2 animations:^{ tmpCell.frame = cell.frame; }completion:^(BOOL finished) { cell.hidden = NO; [tmpCell removeFromSuperview]; }];} 边缘滚动处理 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849- (void)dh_startEdgeScroll{ _edgeScrollTimer = [CADisplayLink displayLinkWithTarget:self selector:@selector(dh_processEdgeScroll)]; [_edgeScrollTimer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];}- (void)dh_processEdgeScroll{ [self dh_gestureChanged:_gesture]; CGFloat minOffsetY = self.contentOffset.y + _edgeScrollRange; CGFloat maxOffsetY = self.contentOffset.y + self.bounds.size.height - _edgeScrollRange; CGPoint touchPoint = _tempView.center; //处理上下达到极限之后不再滚动tableView,其中处理了滚动到最边缘的时候,当前处于edgeScrollRange内,但是tableView还未显示完,需要显示完tableView才停止滚动 if (touchPoint.y < _edgeScrollRange) { if (self.contentOffset.y <= 0) { return; }else { if (self.contentOffset.y - 1 < 0) { return; } [self setContentOffset:CGPointMake(self.contentOffset.x, self.contentOffset.y - 1) animated:NO]; _tempView.center = CGPointMake(_tempView.center.x, _tempView.center.y - 1); } } if (touchPoint.y > self.contentSize.height - _edgeScrollRange) { if (self.contentOffset.y >= self.contentSize.height - self.bounds.size.height) { return; }else { if (self.contentOffset.y + 1 > self.contentSize.height - self.bounds.size.height) { return; } [self setContentOffset:CGPointMake(self.contentOffset.x, self.contentOffset.y + 1) animated:NO]; _tempView.center = CGPointMake(_tempView.center.x, _tempView.center.y + 1); } } //处理滚动 CGFloat maxMoveDistance = 20; if (touchPoint.y < minOffsetY) { //cell在往上移动 CGFloat moveDistance = (minOffsetY - touchPoint.y)/_edgeScrollRange*maxMoveDistance; [self setContentOffset:CGPointMake(self.contentOffset.x, self.contentOffset.y - moveDistance) animated:NO]; _tempView.center = CGPointMake(_tempView.center.x, _tempView.center.y - moveDistance); }else if (touchPoint.y > maxOffsetY) { //cell在往下移动 CGFloat moveDistance = (touchPoint.y - maxOffsetY)/_edgeScrollRange*maxMoveDistance; [self setContentOffset:CGPointMake(self.contentOffset.x, self.contentOffset.y + moveDistance) animated:NO]; _tempView.center = CGPointMake(_tempView.center.x, _tempView.center.y + moveDistance); }}]]></content>
</entry>
<entry>
<title><![CDATA[iOS开发输入框字数限制]]></title>
<url>%2F2017%2F05%2F23%2FiOS%2FiOS%E5%BC%80%E5%8F%91%E8%BE%93%E5%85%A5%E6%A1%86%E5%AD%97%E6%95%B0%E9%99%90%E5%88%B6%2F</url>
<content type="text"><![CDATA[在在网上查了资料,很多都是下面这个方法,但是在原生键盘上是有问题的,当当在手机上英文九宫格连点的时候,会替换掉最后的文字 123456789101112131415161718192021222324252627282930313233343536373839404142[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFieldEditChanged:) name:@"UITextFieldTextDidChangeNotification" object:myTextField];-(void)textFieldEditChanged:(NSNotification *)obj{ UITextField *textField = (UITextField *)obj.object; NSString *toBeString = textField.text; NSString *lang = [textField.textInputMode primaryLanguage]; if ([lang isEqualToString:@"zh-Hans"])// 简体中文输入 { //获取高亮部分 UITextRange *selectedRange = [textField markedTextRange]; UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0]; // 没有高亮选择的字,则对已输入的文字进行字数统计和限制 if (!position) { if (toBeString.length > MAX_STARWORDS_LENGTH) { textField.text = [toBeString substringToIndex:MAX_STARWORDS_LENGTH]; } } } // 中文输入法以外的直接对其统计限制即可,不考虑其他语种情况 else { if (toBeString.length > MAX_STARWORDS_LENGTH) { NSRange rangeIndex = [toBeString rangeOfComposedCharacterSequenceAtIndex:MAX_STARWORDS_LENGTH]; if (rangeIndex.length == 1) { textField.text = [toBeString substringToIndex:MAX_STARWORDS_LENGTH]; } else { NSRange rangeRange = [toBeString rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, MAX_STARWORDS_LENGTH)]; textField.text = [toBeString substringWithRange:rangeRange]; } } }} 经过多次测试后,终于解决了,代码如下: 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253static const int nameMaxLength = 6;@interface FCEditNameViewController ()<UITextFieldDelegate>@property (strong, nonatomic) IBOutlet UITextField *nameTextField;@property (nonatomic, strong) NSString *oldStr;//记录修改之前的值@property (nonatomic, strong) NSString *positionStr;记录高亮的文字@end//当前光标位置 range.location //已选文字长度 range.length - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ if ([string isEqualToString:@""]) { return YES; } //获取高亮部分 UITextRange *selectedRange = [textField markedTextRange]; UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0]; if (!position) { self.oldStr = textField.text; if (range.length + range.location > textField.text.length) { return NO; } NSInteger newStrLength = [textField.text length] + [string length] - range.length; if (newStrLength <= nameMaxLength) { return YES; }else{ return NO; } }else{ if ([self IsChinese:string]) { NSString *str = [NSString stringWithFormat:@"%@%@",self.oldStr,string]; self.oldStr = @""; if (str.length > nameMaxLength) { return NO; }else{ return YES; } } } return YES;}//判断是否有中文- (BOOL)IsChinese:(NSString *)str { for(int i=0; i< [str length];i++){ int a = [str characterAtIndex:i]; if( a > 0x4e00 && a < 0x9fff) { return YES; } } return NO;}]]></content>
</entry>
<entry>
<title><![CDATA[Xcode打断点调试时所有的变量都为nil]]></title>
<url>%2F2017%2F05%2F20%2FiOS%2FXcode%E6%89%93%E6%96%AD%E7%82%B9%E8%B0%83%E8%AF%95%E6%97%B6%E6%89%80%E6%9C%89%E7%9A%84%E5%8F%98%E9%87%8F%E9%83%BD%E4%B8%BAnil%2F</url>
<content type="text"><![CDATA[今天开发的时候打断点进行调试,结果控制台上显示的变量都是nil,例: 解决办法,如图: 将Optimization Level 设为none]]></content>
</entry>
<entry>
<title><![CDATA[AFNetworking的requestSerializer跟responseSerializer]]></title>
<url>%2F2017%2F05%2F16%2FiOS%2FAFNetworking%E7%9A%84requestSerializer%E8%B7%9FresponseSerializer%2F</url>
<content type="text"><![CDATA[requestSerializerrequestSerializer它是AFNetworking参数编码的序列化器: AFHTTPRequestSerializer普通的http的编码格式,二进制 AFJSONRequestSerializerjson编码格式 AFPropertyListRequestSerializerplist编码格式 responseSerializerresponseSerializer它是AFNetworking返回内容编码的序列化器: AFHTTPResponseSerializer普通的http的编码格式,二进制 AFJSONResponseSerializer json编码格式 AFXMLParserRequestSerializer plist编码格式 AFXMLDocumentResponseSerializer XML,只能返回XMLParser,还需要自己解析 AFPropertyListRequestSerializer plist编码格式 AFImageResponseSerializer image AFCompoundRequestSerializer 组合]]></content>
</entry>
<entry>
<title><![CDATA[jQuery的使用]]></title>
<url>%2F2017%2F04%2F26%2Fweb%2FjQuery%E7%9A%84%E4%BD%BF%E7%94%A8%2F</url>
<content type="text"><![CDATA[jQuery DOM操作 jQuery 获取123456$("#btn1").click(function(){ alert("Text: " + $("#test").text());});$("#btn2").click(function(){ alert("HTML: " + $("#test").html());}); 亲自试一试 jQuery 设置123456789$("#btn1").click(function(){ $("#test1").text("Hello world!");});$("#btn2").click(function(){ $("#test2").html("<b>Hello world!</b>");});$("#btn3").click(function(){ $("#test3").val("Dolly Duck");}); 亲自试一试 jQuery 添加 append() - 在被选元素内的结尾插入内容 1$("p").append("Some appended text."); 亲自试一试 prepend() - 在被选元素内的开头插入内容 1$("p").prepend("Some prepended text."); 亲自试一试 after() - 在被选元素之后插入内容 1$("img").after("Some text after"); 亲自试一试 before() - 在被选元素之前插入内容 1$("img").before("Some text before"); 亲自试一试 jQuery 删除 remove() - 删除被选元素(及其子元素) 1$("#div1").remove(); 亲自试一试 empty() - 从被选元素中删除子元素 1$("#div1").empty(); 亲自试一试 jQuery css()设置css属性 1$("p").css("background-color"); 亲自试一试 设置多个css属性 1$("p").css({"background-color":"yellow","font-size":"200%"}); 亲自试一试 jQuery 效果 jQuery 隐藏/显示1234567$("#hide").click(function(){ $("p").hide();});$("#show").click(function(){ $("p").show();}); 亲自试一试 jQuery 淡入淡出 fadeIn() 12345$("button").click(function(){ $("#div1").fadeIn(); $("#div2").fadeIn("slow"); $("#div3").fadeIn(3000);}); 亲自试一试 fadeOut() 12345$("button").click(function(){ $("#div1").fadeOut(); $("#div2").fadeOut("slow"); $("#div3").fadeOut(3000);}); 亲自试一试 fadeToggle() 12345$("button").click(function(){ $("#div1").fadeToggle(); $("#div2").fadeToggle("slow"); $("#div3").fadeToggle(3000);}); 亲自试一试 fadeTo() 12345$("button").click(function(){ $("#div1").fadeTo("slow",0.15); $("#div2").fadeTo("slow",0.4); $("#div3").fadeTo("slow",0.7);}); 亲自试一试 jQuery 滑动 slideDown() slideUp() slideToggle() ]]></content>
</entry>
<entry>
<title><![CDATA[hexo主题代码怎么高亮显示]]></title>
<url>%2F2017%2F03%2F07%2Fother%2Fhexo%E4%B8%BB%E9%A2%98%E4%BB%A3%E7%A0%81%E6%80%8E%E4%B9%88%E9%AB%98%E4%BA%AE%E6%98%BE%E7%A4%BA%2F</url>
<content type="text"><![CDATA[看到很多人跟我一样在按照hexo主题官方文档配置后,结果代码还是不能高亮显示。觉得将它记录下来希望能帮助到刚喜欢用博客来记录东西的朋友。 代码块需要用到两个```,在第一个后面需要加上代码的语言 如图 常用语言对应表 语言 对应代码 Bash bash,sh,zsh C# cs,csharp C++ cpp,c,cc,h,c++,h++,hop CSS css DOS dos,bat,cmd HTML,XML xml,html,xhtml,rss,atom,xjb,xsd,ssl,plist JSON json java java JavaScript javascript, js, jsx Objective-C objectivec, mm, objc, obj-c PHP php, php3, php4, php5, php6 Ruby ruby, rb, gemspec, podspec, thor, irb SQL sql Swift swift VB.Net vbnet, vb]]></content>
</entry>
<entry>
<title><![CDATA[iOS中内存泄漏调试]]></title>
<url>%2F2017%2F02%2F20%2FiOS%2FiOS%E5%86%85%E5%AD%98%E6%B3%84%E6%BC%8F%2F</url>
<content type="text"><![CDATA[iOS开发中,内存问题一直是个长久不变的问题。这不,项目间歇间,用xcode自带的Leak跑了一下程序,发现了几个内存泄漏的地方,都是平时自己没有注意到的,并做出相应改正。在这里记录下。 1.运行程序让程序先跑起来 2.进入Leak工具 如上图,选中show the debug(箭头指的),然后点击Memory 然后点击profile in instruments,通过Leak重新运行程序(弹出框中选择Restart 3.操作Leak工具 如上图,此时程序在跑起来了,Leak Checks右边显示绿色的钩,表示当前没有内存泄漏,这时候我们就可以操作我的app了,跑起来吧,直到发现有红色的X,表示在这里有内存泄漏,如下图 点击红色X,选择Call Tree,如下图 这时候下面的列表会出来很多方法,但都是系统的,表示看不懂有木有啊。。。这时候点击右边中间的选项,然后勾选Call Tree下的Separate by Thread 和 Hide System Libraries,如下图 然后再看左右,下面列表的方法就会变成了我们自己写的方法了,如下图 在这里,有的人肯定会有疑问,为啥他的列表里的方法都是一些进制类的看不懂的,或者就是空白,这是因为Xcode编译项目后,我们会看到一个同名的 dSYM 文件,dSYM 是保存 16 进制函数地址映射信息的中转文件,我们调试的 symbols 都会包含在这个文件中,并且每次编译项目的时候都会生成一个新的 dSYM 文件。显示进制是因为我们的工程build settings 的问题,没有生成dSYM 文件,也就无法解析debug symbols。做法如下图 在Build Options将Debug information Format选择dsYM,这里默认的可能是release下选择的,将debug下也选择就可以了。然后重新从编译,重新运行,从第一步重新走一遍即可出来最后双击列表中暴露出来的方法,会直接显示代码,神不神奇~ 利用这个调试方法,里里外外将我们程序跑一跑,将内存泄漏的地方都改过来,这样程序闪退的机率将会大大减小。 关于product->analyze分析内存泄漏的问题优点:分析速度快,并且可以对所有的代码进行内存分析缺点:分析结果不一定准确(没有运行程序,根据代码的上下文语法结构)所以最好还是用Leak工具进行动态运行检查。 路漫漫其修远兮,吾将上下而求索,与君互勉。]]></content>
</entry>
<entry>
<title><![CDATA[一行代码解决NavigationController多次push问题]]></title>
<url>%2F2017%2F01%2F20%2FiOS%2F%E4%B8%80%E8%A1%8C%E4%BB%A3%E7%A0%81%E8%A7%A3%E5%86%B3NavigationController%E5%A4%9A%E6%AC%A1push%E9%97%AE%E9%A2%98%2F</url>
<content type="text"><![CDATA[新建文件如下 UINavigationController+PushSafe.h 123456#import <UIKit/UIKit.h>@interface UINavigationController(PushSafe)-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated safe:(BOOL)safe;@end UINavigationController+PushSafe.m 123456789101112131415161718192021222324252627282930313233#import "UINavigationController+PushSafe.h"@implementation UINavigationController(PushSafe)-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated safe:(BOOL)safe{ if ([[self.viewControllers lastObject] isKindOfClass:viewController.class]&&safe) { return ; } [self pushViewController:viewController animated:animated];}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view.}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.}*/@end 使用方法 1[self.navigationController pushViewController:chatController animated:YES safe:YES];]]></content>
</entry>
<entry>
<title><![CDATA[导入JPush后上传到svn上再checkout下来项目报错]]></title>
<url>%2F2017%2F01%2F11%2FiOS%2F%E5%AF%BC%E5%85%A5JPush%E5%90%8E%E4%B8%8A%E4%BC%A0%E5%88%B0svn%E4%B8%8A%E5%86%8Dcheckout%E4%B8%8B%E6%9D%A5%E9%A1%B9%E7%9B%AE%E6%8A%A5%E9%94%99%2F</url>
<content type="text"><![CDATA[在项目开发中,导入了激光推送的库,结果上传到svn后再checkout下来项目报错了。这是因为svn默认忽略静态库.a文件。解决办法:cornerstone->Preference 取消打钩 删除.a]]></content>
</entry>
<entry>
<title><![CDATA[解决UIWebView显示HTML字符串特殊符号问题]]></title>
<url>%2F2017%2F01%2F10%2FiOS%2F%E8%A7%A3%E5%86%B3UIWebView%E6%98%BE%E7%A4%BAHTML%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%89%B9%E6%AE%8A%E7%AC%A6%E5%8F%B7%E9%97%AE%E9%A2%98%2F</url>
<content type="text"><![CDATA[做项目时后台传入的HTML字符串本来是 <p><strong>balabalaba</p></strong> 结果被转码成了 &lt;p&gt;&lt;strong&gt;balabalaba&lt;/strong&gt;&lt;/p&gt; 加载到webView显示会有问题,解决办法: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697- (NSString *)stringByDecodingXMLEntities { NSUInteger myLength = [self length]; NSUInteger ampIndex = [self rangeOfString:@"&" options:NSLiteralSearch].location; // Short-circuit if there are no ampersands. if (ampIndex == NSNotFound) { return self; } // Make result string with some extra capacity. NSMutableString *result = [NSMutableString stringWithCapacity:(myLength * 1.25)]; // First iteration doesn't need to scan to & since we did that already, but for code simplicity's sake we'll do it again with the scanner. NSScanner *scanner = [NSScanner scannerWithString:self]; [scanner setCharactersToBeSkipped:nil]; NSCharacterSet *boundaryCharacterSet = [NSCharacterSet characterSetWithCharactersInString:@" \t\n\r;"]; do { // Scan up to the next entity or the end of the string. NSString *nonEntityString; if ([scanner scanUpToString:@"&" intoString:&nonEntityString]) { [result appendString:nonEntityString]; } if ([scanner isAtEnd]) { goto finish; } // Scan either a HTML or numeric character entity reference. if ([scanner scanString:@"&" intoString:NULL]) [result appendString:@"&"]; else if ([scanner scanString:@"'" intoString:NULL]) [result appendString:@"'"]; else if ([scanner scanString:@""" intoString:NULL]) [result appendString:@"\""]; else if ([scanner scanString:@"<" intoString:NULL]) [result appendString:@"<"]; else if ([scanner scanString:@">" intoString:NULL]) [result appendString:@">"]; else if ([scanner scanString:@"&#" intoString:NULL]) { BOOL gotNumber; unsigned charCode; NSString *xForHex = @""; // Is it hex or decimal? if ([scanner scanString:@"x" intoString:&xForHex]) { gotNumber = [scanner scanHexInt:&charCode]; } else { gotNumber = [scanner scanInt:(int*)&charCode]; } if (gotNumber) { [result appendFormat:@"%C", charCode]; [scanner scanString:@";" intoString:NULL]; } else { NSString *unknownEntity = @""; [scanner scanUpToCharactersFromSet:boundaryCharacterSet intoString:&unknownEntity]; [result appendFormat:@"&#%@%@", xForHex, unknownEntity]; //[scanner scanUpToString:@";" intoString:&unknownEntity]; //[result appendFormat:@"&#%@%@;", xForHex, unknownEntity]; NSLog(@"Expected numeric character entity but got &#%@%@;", xForHex, unknownEntity); } } else { NSString *amp; [scanner scanString:@"&" intoString:&amp]; //an isolated & symbol [result appendString:amp]; /* NSString *unknownEntity = @""; [scanner scanUpToString:@";" intoString:&unknownEntity]; NSString *semicolon = @""; [scanner scanString:@";" intoString:&semicolon]; [result appendFormat:@"%@%@", unknownEntity, semicolon]; NSLog(@"Unsupported XML character entity %@%@", unknownEntity, semicolon); */ } } while (![scanner isAtEnd]); finish: return result;}]]></content>
</entry>
<entry>
<title><![CDATA[SDWebImage更新图片缓存的方法]]></title>
<url>%2F2016%2F11%2F20%2FiOS%2FSDWebImage%E6%9B%B4%E6%96%B0%E5%9B%BE%E7%89%87%E7%BC%93%E5%AD%98%E7%9A%84%E6%96%B9%E6%B3%95%2F</url>
<content type="text"><![CDATA[##SDWebImage加载图片,在图片链接相同但图片内容发生变更时,SDWebImage 并不会加载新的图片。此时的解决方案为设置SDWebImage 的option参数为SDWebImageRefreshCached。具体如下图:]]></content>
</entry>
<entry>
<title><![CDATA[Swift怎么通过类名字符串来创建一个类]]></title>
<url>%2F2016%2F09%2F20%2FiOS%2FSwift%E6%80%8E%E4%B9%88%E9%80%9A%E8%BF%87%E7%B1%BB%E5%90%8D%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%9D%A5%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E7%B1%BB%2F</url>
<content type="text"><![CDATA[OC中可以直接通过类名的字符串转换成对应的类来操作,但是Swift中必须用到命名空间,也就是说Swift中通过字符串获取类的方式为1234567891011let namespace = NSBundle.mainBundle().infoDictionary!["CFBundleExecutable"]guard ((namespace as? String) != nil) else{return }let modelClass : AnyClass? = NSClassFromString((namespace as? String)!+"."+modelClassStr)let baseModel = modelClass?.alloc()]]></content>
</entry>
</search>