0421 iPad 泡泡
1. 拖控件
2. 连线
3. 创建tableViewController
4. 实例化pop, 作为成员
![](https://app.yinxiang.com/shard/s21/res/96ae1906-8055-4384-a537-55e4f5742158.png)
5. pop方法
// 箭头朝上,内容就想下,如图:
![](https://app.yinxiang.com/shard/s21/res/eaca6753-9e8d-4765-b399-9b9b99e2dac9.png)
// 下====上 以此类推
Any 会自己决定一个最合适的方向
// so: 一般用Any
![](https://app.yinxiang.com/shard/s21/res/866a1867-f7e7-4478-acff-a8648473cb81.png)
1. 点击按钮时, 保存这个数字
![](https://app.yinxiang.com/shard/s21/res/292c3407-08f5-439f-a239-1416f2bc3c7c.png)
2. 再次输入时,过滤,比如输入1就出来先前输入的内容. // 123 1123 12345
参考之前的笔记:
**************************************
判断是否是qq= 前缀: // hasPrefix,前缀
![](https://app.yinxiang.com/shard/s21/res/fe4f260c-3946-4114-aeee-dd3c1ff3a2e9.png)
类似地,判断结尾:
[str hasSuffix:@“fs”]; // 是的话,返回YES; 否则返回NO
**************************************
// 这里可以用谓词过滤:
![](https://app.yinxiang.com/shard/s21/res/6cd09a9c-38f8-442f-adb7-f90403ba1be3.png)
其他谓词语句:
![](https://app.yinxiang.com/shard/s21/res/bb43fa42-a6d6-46f2-b488-901cede9a655.png)
2个都可以:
用前面,会给你新的数组,原来的数据不变;
而下面的数据会直接覆盖先前的数字.
// so: 选第1个.
![](https://app.yinxiang.com/shard/s21/res/4ded2b1d-abf8-4540-912f-28cfd06b987a.png)
![](https://app.yinxiang.com/shard/s21/res/db3789cc-dd38-4a69-bac0-fa2b2595e9ff.png)
**************************************
扩展:
// 可用用于正则表达式
matches
![](https://app.yinxiang.com/shard/s21/res/f4dc76f3-3b92-48ac-8148-333ccfa6d951.png)
// 过滤出username中的
![](https://app.yinxiang.com/shard/s21/res/775f6bf1-14c8-4469-9cd0-a78e6ad4d854.png)
// 过滤长度为3的
![](https://app.yinxiang.com/shard/s21/res/d3286c7c-a567-4e12-a864-094ae61d8991.png)
**************************************
还可以改进:
连续包含: 比如 12356
输入35 也能联想出来12356
3. 监听用户的输入. // 是系统的通知
![](https://app.yinxiang.com/shard/s21/res/113afa97-071a-436e-b280-6e19b0c170eb.png)
![](https://app.yinxiang.com/shard/s21/res/5318e971-04b7-424d-8efb-925cb24d06dd.png)
4. 完善tableView
5. 泡泡没有数据的时候,隐藏泡泡
if(result.count>0)
6. 记得刷table
![](https://app.yinxiang.com/shard/s21/res/44c529ba-efcf-494d-b6c5-5b35ad77570c.png)
下一阶段:
![](https://app.yinxiang.com/shard/s21/res/5018240f-9206-48b9-b5bd-0fe279cdf7fa.png)
// 需要达到的效果:
点击tableView中的数字, 显示到textField中.
思路:
用通知中心,同时dismiss泡泡
来个好玩的:
// 回去好好研究textkit / mark
attributedText
// 1. 还可以做到:
第一个字变大,后面的不变.
// 2. 还可以做到:
输入1,所有1变红,2所有2 变红.
![](https://app.yinxiang.com/shard/s21/res/ca05806c-0574-4bc0-b20e-f28c5504fbe8.png)
// 效果:
![](https://app.yinxiang.com/shard/s21/res/b290ec1a-0924-4047-acd5-1b82b71b10a3.png)
// 回tableView 处理
![](https://app.yinxiang.com/shard/s21/res/f27632a8-389f-41fd-88db-15b212f8d490.png)
带属性的字符串:
![](https://app.yinxiang.com/shard/s21/res/66d5a738-4c88-42c6-8ddd-4971e3aff98d.png)
修改下面的函数:
// 把长度存起来,参数传进来.
// 修改相关的函数引用
![](https://app.yinxiang.com/shard/s21/res/68eda040-9082-4425-ab2b-ff723401397f.png)
在监听时调用:
// 实例化 tabViewCtl 调用它的方法,给tableView传值...一个是数据源,一个是长度.
[tabViewCtl refreshResult:resultArr length:self.myTF.text.length];
再回到NSMakeRange改变范围
效果图:
![](https://app.yinxiang.com/shard/s21/res/2484c453-a60c-416a-b617-aef0a4ccde7c.png)
部分代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
//cell.textLabel.text = dataArr[indexPath.row];
NSMutableAttributedString * str = [[NSMutableAttributedString alloc]initWithString:dataArr[indexPath.row]];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, _length)];
cell.textLabel.attributedText = str;
//NSLog(@"text--------%@",cell.textLabel.text);
return cell;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
//cell.textLabel.text = dataArr[indexPath.row];
NSMutableAttributedString * str = [[NSMutableAttributedString alloc]initWithString:dataArr[indexPath.row]];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, _length)];
cell.textLabel.attributedText = str;
//NSLog(@"text--------%@",cell.textLabel.text);
return cell;
}