UI第十二天
来源:互联网 发布:淘宝达人淘客佣金设置 编辑:程序博客网 时间:2024/05/03 22:54
注意:
1.block的属性用 copy
2.pch文件 中定义一次,整个工程都能用 注意:Build Setting —>搜索lang —> prefix header —>
$(PROJECT_DIR)/PrefixHeader.pch (相对路径)
3. //设置button上title的颜色
[button setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
4.cell的函数中用到if最好加else
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (table == tableView )
{
NSArray *titleArray = @[@"D",@"F",@"H",@"M",@"W"];
return titleArray[section];
}
else
{
return nil;
}
}
一些概念:
1.反向传值之代理:
委托者中
(1).@protocol ViewController2Delegate <NSObject>
- (void)receiveDataDictionary:(NSMutableDictionary *)dataDic;
@end
(2).@property (assign,nonatomic)id<ViewController2Delegate>delegate;
(3).if ([self.delegaterespondsToSelector:@selector(receiveDataDictionary:)])
{
[self.delegatereceiveDataDictionary:dataDic];
}
代理者中:
(4).遵循代理协议:
<ViewController2Delegate>
(5).建立代理关系:
vc2.delegate = self;
(6).实现协议方法:
- (void)receiveDataDictionary:(NSMutableDictionary *)dataDic
{
// NSLog(@"%@",dataDic);
self.navigationController.navigationBar.barTintColor = [UIColorcolorWithRed:[[dataDic valueForKey:@"red"]floatValue]/255.0green:[[dataDic valueForKey:@"green"]floatValue]/255.0blue:[[dataDic valueForKey:@"blue"]floatValue]/255.0alpha:1.0];
[dataDic1setObject:[dataDic valueForKey:@"name"]forKey:@"name"];
[dataDic1setObject:[dataDic valueForKey:@"pass"]forKey:@"pass"];
[dataDic1setObject:[dataDic valueForKey:@"sex"]forKey:@"sex"];
[dataArray addObject:dataDic1];
// NSLog(@"%@",dataDic1);
// NSLog(@"%@",dataArray);
}
2.反向传值之block:
委托者中:
(1).typedefvoid(^block)(NSMutableDictionary *);
(2).@property (copy,nonatomic)block myBlock;
(3).if (self.myBlock)
{
self.myBlock(dataDic);
}
代理者中:
(4).vc2.myBlock = ^(NSMutableDictionary *dataDic){
self.navigationController.navigationBar.barTintColor = [UIColorcolorWithRed:[[dataDic valueForKey:@"red"]floatValue]/255.0green:[[dataDic valueForKey:@"green"]floatValue]/255.0blue:[[dataDic valueForKey:@"blue"]floatValue]/255.0alpha:1.0];
[dataDic1setObject:[dataDic valueForKey:@"name"] forKey:@"name"];
[dataDic1setObject:[dataDic valueForKey:@"pass"] forKey:@"pass"];
[dataDic1setObject:[dataDic valueForKey:@"sex"] forKey:@"sex"];
[dataArrayaddObject:dataDic1];
[tablereloadData];
};
3.搜索框:
(1).全局 UISearchDisplayController *displayerController;
NSMutableArray *resultArray;//搜索结果数据
(2).UISearchBar *searchBar = [[UISearchBaralloc] initWithFrame:CGRectMake(0,0, 0, 40)];
/*
UISearchBarStyleDefault,
UISearchBarStyleProminent,
UISearchBarStyleMinimal
*/
searchBar.searchBarStyle =UISearchBarStyleMinimal;
searchBar.showsBookmarkButton =YES;
searchBar.placeholder =@"请输入英雄名字:";
searchBar.delegate =self;
//创建搜索控制器
displayerController = [[UISearchDisplayControlleralloc] initWithSearchBar:searchBarcontentsController:self];
displayerController.searchResultsDataSource =self;
displayerController.searchResultsDelegate =self;
// [displayerController.searchResultsTableView reloadData];
resultArray = [NSMutableArrayarray];
table.tableHeaderView = searchBar;
(3).- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (table == tableView)
{
return dataArray.count;
}
else
{
return 1;//结果数组
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == table)
{
return [dataArray[section]count];
}
else
{
return resultArray.count;
}
}
(4).- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID =@"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell)
{
cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellID];
}
if (tableView == table)
{
cell.textLabel.text =dataArray[indexPath.section][indexPath.row];
}
else
{
cell.textLabel.text =resultArray[indexPath.row];
}
return cell;
}
(5).
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if (resultArray.count)
{
[resultArrayremoveAllObjects];
}
NSString *str = searchBar.text;
//清除字符串中的空格
str = [str stringByReplacingOccurrencesOfString:@" "withString:@""];
for (NSArray *tempArrayin dataArray)
{
for (NSString *tempStrin tempArray)
{
NSRange range = [tempStr rangeOfString:str];
//判断数据源字符串中是否含有搜索字符串
if (range.location !=NSNotFound)
{
//如果含有就加入到结果数组中
[resultArrayaddObject:tempStr];
}
}
}
//刷新table
[displayerController.searchResultsTableViewreloadData];
}
- UI第十二天
- UI第十二天:通讯录实战
- iOS-学习笔记-UI-第十二天
- UI第十二课
- 第十二天
- 第十二天
- 第十二天
- 第十二天
- 第十二天
- 第十二天
- Android UI开发第十二篇——动画效果Animation
- Android UI开发第十二篇——动画效果Animation
- Android UI开发第十二篇——动画效果Animation
- UI基础第十二弹: iOS三种简单动画
- 世界杯第十二天
- 第十二天 细描
- 第十二天:听课笔记
- 第十二天:总结
- injection xcode时时调试运行的插件
- poj , hdu习题分类
- reduce()函数
- jquery 弹框插件
- CF 450 B Jzzhu and Sequences(矩阵快速幂)
- UI第十二天
- 数学概念
- mysql 使用order by field() 自定义排序
- 深入理解Java虚拟机笔记---内存区域
- UI第十三天
- 五家共井
- FDDL(Fisher discrimination dictionary learning)学习
- C++分离类模板的声明和定义
- HDU 5015 233 Matrix(构造矩阵)