searchController控制器并没有什么内容,直接实例化了SearchBar
在SearchBar里除了用到了一个UISearchBar,其它还是之前的内容,tableView和TableViewCell,php脚本,xml解析,所以这次重点讲讲UISearchBar
searchBar实例化
-(void)createView{ _searchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(0, 20, self.frame.size.width, 50)]; _searchBar.barStyle=UIBarStyleDefault; _searchBar.keyboardType=UIKeyboardTypeDefault; _searchBar.delegate=self; [self addSubview:_searchBar]; _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 70, self.frame.size.width, self.frame.size.height-100)]; _tableView.dataSource =self; _tableView.delegate=self; [self addSubview:_tableView]; }
//UISerachBar的代理!!!! //点击搜索框事件: -(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{ [searchBar setShowsCancelButton:YES animated:YES]; [searchBar becomeFirstResponder]; self.tableView.allowsSelection=NO; self.tableView.scrollEnabled=NO; } //添加Cancel事件: -(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{ searchBar.text=@""; [searchBar setShowsCancelButton:NO animated:YES]; [searchBar resignFirstResponder]; self.tableView.allowsSelection=YES; self.tableView.scrollEnabled=YES; } //点击Search按钮事件: -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{ [searchBar setShowsCancelButton:NO animated:YES]; [searchBar resignFirstResponder]; self.tableView.allowsSelection=YES; self.tableView.scrollEnabled=YES; [self Search_text:searchBar.text]; }
<span style="font-size:14px;">//读取输入框的内容,并进行搜索 -(void)Search_text:(NSString *)string{ NSString *BasestringUrl=@"http://ashuai.6655.la/SearchBar.php?data"; NSString *Url=[NSString stringWithFormat:@"%@=%@",BasestringUrl,string]; NSLog(@"%@",Url); [self xml_data:Url];//解析Url获取xml数据,再解析xml数据 }</span>
<span style="font-size:14px;">//解析Url获取xml数据 -(void)xml_data:(NSString *)URL{ NSString *url; url = [URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//编码转换!! NSLog(@"%@",url); [AFNetworkTool xmlRequestWithUrl:url success:^(NSXMLParser *xmlParser) { self.xmldata=[NSMutableDictionary dictionary]; xmlParser.delegate = self; [xmlParser setShouldProcessNamespaces:YES]; [xmlParser parse]; NSLog(@"chenggong"); } fail:^{ NSLog(@"xml fail"); UIAlertView *warn=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"网络链接失败!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [warn show]; }]; } </span>
<?php include("xml/sql_dll.php"); $dll=new sql_dll(); if($_GET['data']){ $comic_data=$dll->select_comic($_GET['data']); foreach($comic_data as $echo_comic_data){ $return .="<comic> <video_name> <value>$echo_comic_data[0]</value> </video_name> <video_image> <value>$echo_comic_data[1]</value> </video_image> <video_intro> <value>$echo_comic_data[2]</value> </video_intro> <video_url> <value>$echo_comic_data[3]</value> </video_url> </comic>"; } header("Content-type:text/xml"); echo '<?xml version="1.0" encoding="UTF-8"?> <data> '.$return.' </data>'; exit; } else { print("no data"); } ?>
function select_comic($a) //根据name或者intro进行模糊查询 { $sql="select * from `comic` where `name` LIKE '%$a%' or `intro` LIKE '%$a%'"; return $this->Search($sql); }
暂时动漫App就到这里了,回过头看看自己写的东西,觉得的确有很多欠缺的地方,写文章还是差,
总结,1,xml解析这一块实在是写的太臃肿了,用json数据在Afnetworking的方法中就能方便的获取数据,不需要再使用xml解析的代理,
2,关于动漫和动画的tableview,没有上拉刷新or下拉刷新的功能
3,页面约束也是很遗憾,应该用一下比较流行的masony框架
4,比较欣慰的是自己写了几个控件(自定义的tabbar,图片循环播放,虽然不如第三方框架),和一个图片下载的方法(虽然不如SDwebimage)