当前位置: 首页 > 编程日记 > 正文

UISearchBar和 UISearchDisplayController的使用

感觉好多文章不是很全面,所以本文收集整合了网上的几篇文章,感觉有互相补充的效果。

如果想下载源码来看:http://code4app.com/search/searchbar 。本源码与本文无关

1、searchBar

本例子实现布局:上面是一个navigationController,接下来一个searchBar,下面是tableView

searchBar这个控件就用来搜索tableView上的数据

[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];

UISearchDisplayController这个控件很强大,它初始化是基于searchBar的,里面有些效果很不错,apple都封装好了,并且可以很好的支持实时搜索,即我们只需要将搜索出来的数据重新赋给array(这个array用来存储tableView数据),不需要reloadData,就会自动出来

其实reloadData也没用,为什么呢?因为搜索出来的结果显示在tableView上,该tableView并不是当前布局的那个tableView,而是另外一个,我猜测应该是UISearchDisplayController里面自带的,所以不要混淆了

特别是在tableView代理方法里,有时候需要判断代理方法传入的tableView是否为当前布局的tableView,因为也有可能是UISearchDisplayController里自带的,它们同样会触发代理方法

当点击searchBar时,它会自动上移并且遮住navigationController

经过测试,如果上面是navigationBar,则searchBar不会移动,但如果是UINavigationController自带过来的,则会上移覆盖

往往有的时候都是UINavigationController自带过来的,如果使用UISearchDisplayController,searchBar就会自动覆盖,这个情况我试了很多次,包括新创建了一个navigationBar盖在上面,但效果依然不好,对于这种情况,基于我目前的技术,只能舍弃UISearchDisplayController,单纯的用UISearchBar了,虽然效果差了一些,但需要实现的功能照样可以,比如实时搜索,除了重新赋值给array外,额外的操作就是需要reloadData了。

有时候点击searchBar时,右侧可能没有出现‘cancel/取消’按钮,这时需要调用下面的方法

- (void)setShowsCancelButton:(BOOL)showsCancelButton animated:(BOOL)animated

相信看方法名字就知道是做什么的了

来源:http://www.cnblogs.com/mobiledevelopment/archive/2011/08/04/2127633.html

2、iOS开发 给TableView增加SearchBar

效果如图:

可以根据输入的关键字,在TableView中显示符合的数据。
图中分组显示和索引效果,前面的博文已经记录,不再赘述。下面的例子是基于前文的基础上修改的,所以文件名啥的,请参考前文。
第一步是在TableView上方添加一个Search Bar,这里有一点需要注意,必须先把TableView拖下来,留下空间放Search Bar,不要在Table View占满屏幕的情况下把Search Bar拖到Table View顶部。区别在于,使用后面的方法,Search Bar是作为Table View的Header部分添加的,而前面的方法,Search Bar是独立的。在添加索引功能时,如果作为Table View的Header添加,右侧的索引会遮住Search Bar的右边部分。Search Bar几个常用属性:
Placeholder是提示,就是hint属性,Corretion是自动修正,一般设为NO,即不修正,Show Cancel Button是显示取消按钮,我这里勾选。选中Search Bar的情况下切换到Connections Inspector面板,delegate与File’s Owner建立连接(我们会在ViewController中支持UISearchBarDelegate协议)。与前面几篇文章的例子相同,ViewController文件名为PDViewController.h和PDViewController.m。
第二步,添加Table View和Search Bar的Outlet.按住Control键,分别拖动Table View和Search Bar到PDViewController.h,添加Outlet
第三步,就是PDViewController代码:
PDViewController.h:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#import <UIKit/UIKit.h>@interface PDViewController : UIViewController<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate>
@property (strong,nonatomic) NSDictionary *names;
@property (strong,nonatomic) NSMutableDictionary *mutableNames;
@property (strong,nonatomic)NSMutableArray *mutableKeys;
//可变字典和可变数组,用于存储显示的数据,而不可变的字典用于存储从文件中读取的数据
@property (strong, nonatomic) IBOutlet UITableView *table;
@property (strong, nonatomic) IBOutlet UISearchBar *search;
-(void)resetSearch;
//重置搜索,即恢复到没有输入关键字的状态
-(void)handleSearchForTerm:(NSString *)searchTerm;
//处理搜索,即把不包含searchTerm的值从可变数组中删除@end

PDViewController.m:

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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#import "PDViewController.h"
#import "NSDictionary+MutableDeepCopy.h"@implementation PDViewController
@synthesize names=_names;
@synthesize mutableKeys=_mutableKeys;
@synthesize table = _table;
@synthesize search = _search;
@synthesize mutableNames=_mutableNames;
- (void)didReceiveMemoryWarning
{[super didReceiveMemoryWarning];// Release any cached data, images, etc that aren't in use.
}#pragma mark - View lifecycle- (void)viewDidLoad
{[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.NSString *path=[[NSBundle mainBundle] pathForResource:@"sortednames" ofType:@"plist"];//取得sortednames.plist绝对路径//sortednames.plist本身是一个NSDictionary,以键-值的形式存储字符串数组NSDictionary *dict=[[NSDictionary alloc] initWithContentsOfFile:path];//转换成NSDictionary对象self.names=dict;[self resetSearch];//重置[_table reloadData];//重新载入数据}- (void)viewDidUnload
{[self setTable:nil];[self setSearch:nil];[super viewDidUnload];self.names=nil;self.mutableKeys=nil;self.mutableNames=nil;// Release any retained subviews of the main view.// e.g. self.myOutlet = nil;
}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{// Return YES for supported orientationsreturn (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{//返回分组数量,即Array的数量return [_mutableKeys count];//}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{if ([_mutableKeys count]==0) {return 0;}NSString *key=[_mutableKeys objectAtIndex:section];NSArray *nameSection=[_mutableNames objectForKey:key];return [nameSection count];//返回Array的大小}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{NSUInteger section=[indexPath section];//分组号NSUInteger rowNumber=[indexPath row];//行号//即返回第section组,rowNumber行的UITableViewCellNSString *key=[_mutableKeys objectAtIndex:section];//取得第section组array的keyNSArray *nameSection=[_mutableNames objectForKey:key];//通过key,取得Arraystatic NSString * tableIdentifier=@"CellFromNib";UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tableIdentifier];if(cell==nil){cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableIdentifier];}cell.textLabel.text=[nameSection objectAtIndex:rowNumber]; //从数组中读取字符串,设置textreturn cell;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{if ([_mutableKeys count]==0) {return 0;}NSString *key=[_mutableKeys objectAtIndex:section];return key;
}
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{return _mutableKeys;//通过key来索引
}
-(void)resetSearch
{//重置搜索_mutableNames=[_names mutableDeepCopy];//使用mutableDeepCopy方法深复制NSMutableArray *keyarr=[NSMutableArray new];[keyarr addObjectsFromArray:[[_names allKeys] sortedArrayUsingSelector:@selector(compare:)]];//读取键,排序后存放可变数组_mutableKeys=keyarr;}
-(void)handleSearchForTerm:(NSString *)searchTerm
{//处理搜索NSMutableArray *sectionToRemove=[NSMutableArray new];//分组待删除列表[self resetSearch];//先重置for(NSString *key in _mutableKeys){//循环读取所有的数组NSMutableArray *array=[_mutableNames valueForKey:key];NSMutableArray *toRemove=[NSMutableArray new];//待删除列表for(NSString *name in array){//数组内的元素循环对比if([name rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location==NSNotFound){//rangeOfString方法是返回NSRange对象(包含位置索引和长度信息)//NSCaseInsensitiveSearch是忽略大小写//这里的代码会在name中找不到searchTerm时执行[toRemove addObject:name];//找不到,把name添加到待删除列表}}if ([array count]==[toRemove count]) {[sectionToRemove addObject:key];//如果待删除的总数和数组元素总数相同,把该分组的key加入待删除列表,即不显示该分组}[array removeObjectsInArray:toRemove];//删除数组待删除元素}[_mutableKeys removeObjectsInArray:sectionToRemove];//能过待删除的key数组删除数组[_table reloadData];//重载数据}
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{//TableView的项被选择前触发[_search resignFirstResponder];//搜索条释放焦点,隐藏软键盘return indexPath;
}
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{//按软键盘右下角的搜索按钮时触发NSString *searchTerm=[searchBar text];//读取被输入的关键字[self handleSearchForTerm:searchTerm];//根据关键字,进行处理[_search resignFirstResponder];//隐藏软键盘}
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{//搜索条输入文字修改时触发if([searchText length]==0){//如果无文字输入[self resetSearch];[_table reloadData];return; }[self handleSearchForTerm:searchText];//有文字输入就把关键字传给handleSearchForTerm处理
}
-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{//取消按钮被按下时触发[self resetSearch];//重置searchBar.text=@"";//输入框清空[_table reloadData];[_search resignFirstResponder];//重新载入数据,隐藏软键盘}@end

mutableDeepCopy深复制的方法在NSDictionary+MutableDeepCopy定义,参考iOS/Objective-C开发 字典NSDictionary的深复制(使用category)

3、Search Bar and Search DisplayController的实现

新建Navigation-based Project。打开.xib文件,拖一个Search Bar and Search DisplayController 对象到Table View对象上方,如下图所示,选中File’s Owner ,打开Connections面板:

现在我们来创建Search Bar和SearchDisplay Controller的出口。打开Assistant Editor,按住ctrl键,将SearchDisplay Controller拖到ViewController 的头文件中。创建一个名为searchDisplayController的出口,然后点Connect。

同样的方法为Search Bar创建连接。现在ViewController的头文件看起来像这样:

#import <UIKit/UIKit.h>

@interface RootViewController : UITableViewController {

UISearchDisplayController *searchDisplayController;     UISearchDisplayController *searchBar;

NSArray *allItems;

NSArray *searchResults;

}

@property (nonatomic, retain) IBOutlet UISearchDisplayController *searchDisplayController;

@property (nonatomic, retain) IBOutlet UISearchDisplayController *searchBar;

@property (nonatomic, copy) NSArray *allItems;

@property (nonatomic, copy) NSArray *searchResults;

@end

你可能注意到,我初始化了两个NSArray。一个用于作为数据源,一个用于保存查找结果。在本文中,我使用字符串数组作为数据源。继续编辑.m文件前,别忘了synthesize相关属性:

@synthesize searchDisplayController;

@synthesize searchBar;

@synthesize allItems;

@synthesize searchResults;

在viewDidLoad 方法中,我们构造了我们的字符串数组:

- (void)viewDidLoad {

[super viewDidLoad];

// [self.tableView reloadData];

self.tableView.scrollEnabled = YES;

NSArray *items = [[NSArray alloc] initWithObjects:                       @"Code Geass",                       @"Asura Cryin'",                       @"Voltes V",                       @"Mazinger Z",                       @"Daimos",                       nil];

self.allItems = items;

[items release];

[self.tableView reloadData];

}

在Table View的返回TableView行数的方法中,我们先判断当前Table View是否是searchDisplayController的查找结果表格还是数据源本来的表格,然后返回对应的行数:

- (NSInteger)tableView:(UITableView *)tableView   numberOfRowsInSection:(NSInteger)section {

NSInteger rows = 0;

if ([tableView           isEqual:self.searchDisplayController.searchResultsTableView]){

rows = [self.searchResults count];

}else{

rows = [self.allItems count];

}

return rows;

}

在tableView:cellForRowAtIndexPath:方法里,我们需要做同样的事:

// Customize the appearance of table view cells.

- (UITableViewCell *)tableView:(UITableView *)tableView           cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView                               dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[[UITableViewCell alloc]                   initWithStyle:UITableViewCellStyleDefault                   reuseIdentifier:CellIdentifier] autorelease];

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

}

/* Configure the cell. */

if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]){

cell.textLabel.text = [self.searchResults objectAtIndex:indexPath.row];

}else{

cell.textLabel.text = [self.allItems objectAtIndex:indexPath.row];

}

return cell;

}

现在来实现当搜索文本改变时的回调函数。这个方法使用谓词进行比较,并讲匹配结果赋给searchResults数组:

- (void)filterContentForSearchText:(NSString*)searchText                               scope:(NSString*)scope {

NSPredicate *resultPredicate = [NSPredicate                                      predicateWithFormat:@"SELF contains[cd] %@",                                     searchText];

self.searchResults = [self.allItems filteredArrayUsingPredicate:resultPredicate];

}

接下来是UISearchDisplayController的委托方法,负责响应搜索事件:

#pragma mark - UISearchDisplayController delegate methods

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller  shouldReloadTableForSearchString:(NSString *)searchString {

[self filterContentForSearchText:searchString                                 scope:[[self.searchDisplayController.searchBar scopeButtonTitles]                                       objectAtIndex:[self.searchDisplayController.searchBar                                                      selectedScopeButtonIndex]]];

return YES;

}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller  shouldReloadTableForSearchScope:(NSInteger)searchOption {

[self filterContentForSearchText:[self.searchDisplayController.searchBar text]                                 scope:[[self.searchDisplayController.searchBar scopeButtonTitles]                                       objectAtIndex:searchOption]];

return YES;

}

运行工程,当你在搜索栏中点击及输入文本时,如下图所示:

4、UISearchBar的使用以及下拉列表框的实现

在IOS混饭吃的同志们都很清楚,搜索框在移动开发应用中的地位。今天我们就结合下拉列表框的实现来聊聊UISearchBar的使用。本人新入行的菜鸟一个,不足之处请多多指教。直接上代码。

UISearchBar控件的声明:(在控制器DownListViewController中)

  1. @property (nonatomic,retain) UISearchBar* searchBar;

控件的初始化:

  1. _searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 320, 40)]; 
  2. _searchBar.placeholder = @"test";   //设置占位符 
  3. _searchBar.delegate = self;   //设置控件代理 

当然,做完这些工作之后,我们还要在将控件添加到父视图之上,也可以把他设置成UITableView的tableHeaderView属性值,由于大家需求不一,这里就不再给出代码。

前面,我们设置了控件的代理,当然我们必须让控制器(DownListViewController)的 .h 文件实现 UISearchBarDelegate 协议,然后我们继续, 我们要在 .m 文件中实现协议方法:

  1. #pragma mark -
  2. #pragma mark UISearchBarDelegate
  3. //搜索框中的内容发生改变时 回调(即要搜索的内容改变)
  4. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
  5. NSLog(@"changed");
  6. if (_searchBar.text.length == 0) { 
  7. [self setSearchControllerHidden:YES]; //控制下拉列表的隐现
  8. }else{
  9. [self setSearchControllerHidden:NO];
  10. }
  11. }
  12. - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
  13. searchBar.showsCancelButton = YES; 
  14. for(id cc in [searchBar subviews])
    {
    if([cc isKindOfClass:[UIButton class]])
    {
    UIButton *btn = (UIButton *)cc;
    [btn setTitle:@"取消" forState:UIControlStateNormal];
    }
    }
  15. NSLog(@"shuould begin");
  16. return YES;
  17. }
  18. - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
  19. searchBar.text = @""; 
  20. NSLog(@"did begin");
  21. }
  22. - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
  23. NSLog(@"did end");
  24. searchBar.showsCancelButton = NO; 
  25. }
  26. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
  27. NSLog(@"search clicked");
  28. }
  29. //点击搜索框上的 取消按钮时 调用
  30. - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
  31. NSLog(@"cancle clicked");
  32. _searchBar.text = @""; 
  33. [_searchBar resignFirstResponder];
  34. [self setSearchControllerHidden:YES];
  35. }

至此,搜索框的实现就搞定了,怎么样简单吧。下面我们来讲讲下拉列表框的实现,先说说他的实现原理或者是思路吧。下拉列表框我们用一个控制器来实现,我们新建一个控制器SearchViewController.

  1. @interface SearchViewController : UITableViewController 
  2. @end

在 .m 文件中,我们实现该控制器

  1. - (id)initWithStyle:(UITableViewStyle)style
  2. {
  3. self = [super initWithStyle:style]; 
  4. if (self) {
  5. // Custom initialization
  6. }
  7. return self;
  8. }
  9. - (void)viewDidLoad
  10. {
  11. [super viewDidLoad];
  12. self.tableView.layer.borderWidth = 1; 
  13. self.tableView.layer.borderColor = [[UIColor blackColor] CGColor]; 
  14. }

然后实现控制器的数据源,

  1. #pragma mark -
  2. #pragma mark Table view data source
  3. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  4. return 1;
  5. }
  6. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  7. // 返回列表框的下拉列表的数量
  8. return 3;
  9. }
  10. // Customize the appearance of table view cells.
  11. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  12. static NSString *CellIdentifier = @"Cell"; 
  13. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
  14. if (cell == nil) { 
  15. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ; 
  16. }
  17. // Configure the cell...
  18. NSUInteger row = [indexPath row]; 
  19. cell.textLabel.text = @"down list"; 
  20. return cell;
  21. }

这样列表框的控制器就实现了。接下来我们就来看看怎么让出现、隐藏。这点我们利用UIView的动画效果来实现,我们在DownListViewController控制器中 增加一个方法:

  1. - (void) setSearchControllerHidden:(BOOL)hidden {
  2. NSInteger height = hidden ? 0: 180; 
  3. [UIView beginAnimations:nil context:nil];
  4. [UIView setAnimationDuration:0.2];
  5. [_searchController.view setFrame:CGRectMake(30, 36, 200, height)];
  6. [UIView commitAnimations];
  7. }

我们只需调用该方法就可以了。现在我们看看DownListViewController的布局方法

  1. - (void)viewDidLoad
  2. {
  3. [super viewDidLoad];
  4. _searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 320, 40)]; 
  5. _searchBar.placeholder = @"test"; 
  6. _searchBar.delegate = self;  
  7. _tableview = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain]; 
  8. _tableview.dataSource = self; 
  9. _tableview.tableHeaderView = _searchBar; 
  10.  _searchController = [[SearchViewController alloc] initWithStyle:UITableViewStylePlain]; 
  11.     [_searchController.view setFrame:CGRectMake(30, 40, 200, 0)]; 
  12. [self.view addSubview:_tableview];
  13. [self.view addSubview:_searchController.view];
  14. }

这样一切都搞定了。

好了,总结一下:

我们用了两个控制器:DownListViewController(搜索框的实现 和 控制下拉列表框的出现与隐藏)和SearchViewController(下拉列表框的实现)。在DownListViewController中我们声明并初始化 UISearchBar和SearchViewController(高度开始设置为零),用动画来实现下拉列表框的出现与隐藏。

本文出自 “开发问道” 博客,请务必保留此出处http://izhuaodev.blog.51cto.com/6266344/1102408

转载于:https://www.cnblogs.com/langtianya/p/4114532.html

相关文章:

iOS 获取指定时间的前后N个月

https://www.cnblogs.com/SUPER-F/p/7298548.html 正数为后 负数为前 -(NSDate *)getPriousorLaterDateFromDate:(NSDate *)date withMonth:(NSInteger)month { NSDateComponents *comps [[NSDateComponents alloc] init]; [comps setMonth:month]; NSCalendar *calender …

JS高级程序设计第五章读书笔记

1.引用类型的值&#xff08;对象&#xff09;是引用类型的一个实例。在ES中&#xff0c;引用类型是一种数据结构&#xff0c;用于将数据和功能组织在一起。它们也长被称为类&#xff0c;但这并不妥当。因为ES在技术层面上是一门面对对象的语言&#xff0c;但它并不具备传统的面…

使用Tape和Vue Test Utils编写快速的Vue单元测试

by Edd Yerburgh埃德耶堡(Edd Yerburgh) 使用Tape和Vue Test Utils编写快速的Vue单元测试 (Write blazing fast Vue unit tests with Tape and Vue Test Utils) Tape is the fastest framework for unit testing Vue components.磁带是用于Vue组件进行单元测试的最快框架。 I…

js去除数组中重复值

//第三种方法加强版 Array.prototype.distinctfunction(){ var sameObjfunction(a,b){ var tag true; if(!a||!b)return false; for(var x in a){ if(!b[x]) return false; if(typeof(a[x])object){ tagsameObj(a[x],b[x]); }else{ if(a[x]!b[x]) return false; } } return ta…

CXFServlet类的作用

CXFServlet是Apache CXF框架中的一个核心组件,用于处理HTTP请求并将它们转换为Web服务调用。通过配置CXFServlet,你可以轻松地部署和管理SOAP和RESTful Web服务。

了解jvm对编程的帮助_这是您对社会责任编程的了解

了解jvm对编程的帮助by ?? Anton de Regt由?? 安东德雷格 这是您对社会责任编程的了解 (This is what you need to know about Socially Responsible Programming) 您的才华比银行帐户中的零值多 (Your talent is worth more than lots of zeroes in your bank account) L…

解压和生成 system.imgdata.img ( ext4格式)

另一篇文章讲述了如何解压和生成system.img&#xff0c; 那是针对yaffs2格式的文件系统镜像。 目前越来越多的Android手机放弃了nand, 更多采用了emmc为内部存储设备。 以emmc为存储设备的android手机&#xff0c;其文件系统(/system,/data两个分区&#xff09;一般采用ext4格式…

简单分析beyond作曲

本人绝对是业余的哈 业余到什么水平呢&#xff1f;正在练习爬格子&#xff0c;还是一个星期练几次那种 先说下《海阔天空》 6&#xff0c;5&#xff0c;4&#xff0c;3 1&#xff0c;2&#xff0c;3&#xff0c;4 简单是简单得不得了&#xff0c;声从低到高&#xff0c;然后再从…

1 OC 对象的本质(一个NSObject 对象占用的内存大小)

1 前言 目录 1 前言 2 一个NSObject占用多少内存 3 为什么呢 &#xff1f; 4 如何在内存中看呢&#xff1f; OC 的面向对象都是基于C/C 的数据结构实现的 结构体 2 clang 命令转换成c 代码 clang -rewrite-objc main.m -o main.cpp 以上的命令是不分平台进行编译的&…

Xiki:一个开发人员寻求增强命令行界面的能力

by Craig Muth通过克雷格穆斯(Craig Muth) Xiki&#xff1a;一个开发人员寻求增强命令行界面的能力 (Xiki: one developer’s quest to turbocharge the command line interface) I was sitting with my friend Charles in a trendy cafe next to Golden Gate Park in San Fra…

2 OC 对象的本质(一个Student 占用的内存大小)

一 Student 占用的内存空间 补充&#xff1a; 1 成员变量占用字节的大小&#xff1a; 2 内存对齐的规则&#xff1a;结构体的内存大小必须是最大成员变量的内存的倍数。 一个 Student 类,继承自NSObject&#xff0c;有两个属性&#xff0c;首先要知道&#xff0c;int 类型占用…

jdk动态代理源码学习

最近用到了java的动态代理&#xff0c;虽然会用&#xff0c;但不了解他具体是怎么实现&#xff0c;抽空看看了看他的源码。 说到Java的动态代理就不能不说到代理模式&#xff0c;动态代理也就是多了一个’动态’两字,在《大话设计模式》中不是有这句话吗&#xff1f;“反射&…

20162313苑洪铭 第一周作业

20162313苑洪铭 20016-2017-2 《程序设计与数据结构》第1周学习总结 教材学习内容总结 本周观看教材绪论 主要在教我建立一个简单的java程序 内容是林肯的名言 虽然看起来很简单 但是实际上问题重重 总而言之 这一周全是在出现故障的 教材学习中的问题和解决过程 教材学习好像并…

测试驱动开发 测试前移_测试驱动的开发可能看起来是工作的两倍-但无论如何您都应该这样做...

测试驱动开发 测试前移by Navdeep Singh通过Navdeep Singh 测试驱动的开发可能看起来是工作的两倍-但无论如何您都应该这样做 (Test-driven development might seem like twice the work — but you should do it anyway) Isn’t Test Driven Development (TDD) twice the wor…

3 OC 属性和方法

1 OC 的属性的生成 interface Student:NSObject {publicint _no;int _age;}property (nonatomic,assign)int height;end 当我们使用property 的时候&#xff0c;那么系统会自动的在其内部生成个属性 xcrun -sdk iphoneos clang -arch arm64 -rewrite-objc main.m -o main.c…

ios绘图时的坐标处理

在iOS中&#xff0c;进行绘图操作时&#xff0c;一般主要是在UIView:drawRect中调用 UIGraphicsBeginImageContextWithOptions等一系列函数&#xff0c;有时候直接画图就行&#xff0c;比如UIImage的drawRect等&#xff0c;有时候需要进行稍微复杂的操作&#xff0c;比如颜色混…

mongoDB数据库操作工具库

/* Mongodb的数据库工具类 */ var client require(mongodb).MongoClient;function MongoUtil() { this.url"mongodb://localhost:27017/storage";//在本地新建数据库storage&#xff0c;此后插入的数据都在storage中 }MongoUtil.prototype.connectfunction(callback…

开源许可证 如何工作_开源许可证的工作方式以及如何将其添加到您的项目中...

开源许可证 如何工作by Radu Raicea由Radu Raicea 开源许可证的工作方式以及如何将其添加到您的项目中 (How open source licenses work and how to add them to your projects) Recently, there was some exciting news for developers around the world. Facebook changed t…

通过API文档查询Math类的方法,打印出近似圆,只要给定不同半径,圆的大小就会随之发生改变...

package question;import java.util.Scanner; import java.lang.Math;public class MathTest {/*** 未搞懂* param args*/public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.println("请输入圆的半径:");Scanner in new Scanne…

4 OC 中的内存分配以及内存对齐

目录 一 OC 中的内存分配 一 OC 中的内存分配 student 结构体明明是20&#xff1f;为什么是24个字节&#xff0c;因为结构体会按照本身成员变量最大的内存进行对齐&#xff0c;最大成员变量是8个字节&#xff0c;因此就是8的倍数&#xff0c;24个字节。 class_getInstanc…

JDE函数--GetUDC(B函数)

GetUDC使用方式&#xff1a; 转载于:https://www.cnblogs.com/GYoungBean/p/4117965.html

k8s crd构建方法_告诉您正在构建没人想要的东西的8种方法(以及处理方法)

k8s crd构建方法by Geoffrey Bourne杰弗里伯恩(Geoffrey Bourne) 告诉您正在构建没人想要的东西的8种方法(以及处理方法) (8 ways to tell you’re building something nobody wants (and what to do about it)) Building something users want is hard — damn hard. They ar…

iOS开发 - 线程与进程的认识与理解

进程&#xff1a; 进程是指在系统中正在运行的一个应用程序&#xff0c;比如同时打开微信和Xcode&#xff0c;系统会分别启动2个进程;每个进程之间是独立的&#xff0c;每个进程均运行在其专用且受保护的内存空间内;线程&#xff1a; 一个进程要想执行任务&#xff0c;必须得有…

Winform开发中常见界面的DevExpress处理操作

我们在开发Winform程序的时候&#xff0c;需要经常性的对界面的一些控件进行初始化&#xff0c;或者经常简单的封装&#xff0c;以方便我们在界面设计过程中反复使用。本文主要介绍在我的一些项目中经常性的界面处理操作和代码&#xff0c;以便为大家开发的时候提供必要的参考。…

5 OC 中的三种对象

目录 OC 中对象的分类 一 instance 对象 二 类对象 三 元类对象 总结: OC 中对象的分类 instance 对象 类对象 元类对象 一 instance 对象 内存中包含哪些信息 isa 指针 其他成员的变量Student *stu1 [[Student alloc]init]; 以上的stu1 就是实例对象 二 类对象 以…

travis ci_如何使用Travis CI和GitHub进行Web开发工作流程

travis ciby Vijayabharathi Balasubramanian通过Vijayabharathi Balasubramanian 如何使用Travis CI和GitHub进行Web开发工作流程 (How to use Travis CI and GitHub for your web development workflow’s heavy lifting) It’s common to hack together apps on CodePen wh…

android.view.ViewRoot$CalledFromWrongThreadException的解决办法

android 是不允许子线程直接更新UI的&#xff0c;如果一定要在子线程直接更新UI就会出现android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.大概意思就是说 只有原来创建找个视图hierarchy的…

6 OC中 isa 和 superclass 的总结

目录 一 关于isa 和 superclass 的总结 二 为什么基类的metaclass 的superclass 指向的是基类的类 三 isa 的细节问题 总结如下&#xff1a; instance 的isa 指向是classclass 的isa 指向是metaclassmetaclass 的isa指向是基类的imetaclassclass 的superclass 指向的是父类…

opencv下指定文件夹下的图片灰度化(图片的读取与保存)-------简单记录

对于此功能其实很简单&#xff1a;主要是在c方面的字母数字的拼接问题存在一定的问题。C数字字母拼接问题&#xff1a; 1 #include <fstream> 2 #include <string> 3 #include <iostream> 4 #include "highgui.h" 5 #include <cv.h> 6 #…