Iphone 搜索栏没有';无法在ios中的设备上工作
我创建了iOS(5.0)应用程序,因为我有搜索栏,用于搜索服务器端的内容,同时将输入的关键字传递到搜索栏,搜索栏是从xml解析的内容列表,并显示在表视图中 它在Emulator中运行良好,但在设备(ipad2和iphone4s)中,它没有显示内容表 请让我知道我做错了什么 提前谢谢 穆拉里 这是我的搜索课Iphone 搜索栏没有';无法在ios中的设备上工作,iphone,ios,Iphone,Ios,我创建了iOS(5.0)应用程序,因为我有搜索栏,用于搜索服务器端的内容,同时将输入的关键字传递到搜索栏,搜索栏是从xml解析的内容列表,并显示在表视图中 它在Emulator中运行良好,但在设备(ipad2和iphone4s)中,它没有显示内容表 请让我知道我做错了什么 提前谢谢 穆拉里 这是我的搜索课 @interface SearchClass : UIViewController<UITableViewDelegate,UITableViewDataSource,UIPickerV
@interface SearchClass : UIViewController<UITableViewDelegate,UITableViewDataSource,UIPickerViewDelegate,UIPickerViewDataSource,UIActionSheetDelegate,UISearchBarDelegate, UISearchDisplayDelegate>
{
AppDelegate *abc;
MBProgressHUD *HUD;
IBOutlet UIScrollView *scrv;
IBOutlet UITableView *tableV;
UISearchBar *searchBar;
IBOutlet UILabel *lblTitle;
IBOutlet UIActionSheet *actionSheet;
IBOutlet UIPickerView *pickerView;
IBOutlet UIButton *btnActionSheet;
UIToolbar *pickerToolBar;
NSMutableArray *arrCate;
NSString *key;
}
-(void)cleartable;
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar;
@end
@界面搜索类:UIViewController
{
AppDelegate*abc;
MBHUD*HUD;
IB-UIScrollView*scrv;
IBUITableView*表五;
UISearchBar*搜索栏;
IBUILabel*lblTitle;
IBUIActionSheet*actionSheet;
IBUIPickerView*pickerView;
IBUIButton*btnActionSheet;
UIToolbar*选择器Toolbar;
NSMUTABLEARRY*arrCate;
NSString*键;
}
-(无效)可清除;
-(无效)searchBarSearchButtonClicked:(UISearchBar*)搜索栏;
@结束
//======================
这是我的班级
@implementation SearchClass
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.tabBarItem.image = [UIImage imageNamed:@"search"];
UIImageView *navImg=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"i-street"]];
self.navigationItem.titleView = navImg;
}
return self;
}
- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg1.png"]];
abc = (AppDelegate*)[[UIApplication sharedApplication]delegate];
//self.navigationController.navigationBar.tintColor = [UIColor blackColor];
//[SearchClass initWithNibName:@"" bundle:nil];
//[SearchClass initWithNibName:@"SearchClass" bundle:nil];
arrCate = [[NSMutableArray alloc]initWithObjects:@"Arts & Entertainment",@"Restaurants",@"Bars, Pubs & Clubs",@"Film and Cinema",@"Live Gigs",@"Shops", nil];
pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 43 , 320, 480)];
pickerView.delegate = self;
pickerView.dataSource = self;
[pickerView setShowsSelectionIndicator:YES];
pickerToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 56)];
pickerToolBar.barStyle = UIBarStyleBlackOpaque;
[pickerToolBar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIButton *btnDone = [UIButton buttonWithType:UIButtonTypeCustom];
[btnDone setFrame:CGRectMake(0, 0, 60, 30)];
[btnDone addTarget:self action:@selector(closeActionSheet) forControlEvents:UIControlEventTouchUpInside];
[btnDone setBackgroundImage:[UIImage imageNamed:@"done.png"] forState:UIControlStateNormal];
UIBarButtonItem *dbtn = [[UIBarButtonItem alloc]initWithCustomView:btnDone];
[barItems addObject:dbtn];
[pickerToolBar setItems:barItems animated:YES];
}
-(IBAction)closeActionSheet
{
lblTitle.text=[arrCate objectAtIndex:[pickerView selectedRowInComponent:0]];
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [arrCate objectAtIndex:row];
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component
{
return [arrCate count];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent: (NSInteger)component
{
lblTitle.text = [arrCate objectAtIndex:row];
[abc.arrSearch removeAllObjects];
[tableV reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// NSLog(@"table view count seasrch :%d",[abc.arrSearch count]);
return [abc.arrSearch count];
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
NSString *imgUrl;
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
else
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
if(indexPath.row > 0)
{
UIImageView *separator = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"line1.png"]];
[cell.contentView addSubview: separator];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIImageView *imgbest=[[UIImageView alloc]initWithFrame:CGRectMake(213,4,107,64)];
UIActivityIndicatorView *actSpiner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
actSpiner.center = imgbest.center;
[actSpiner startAnimating];
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(5, 2, 200, 20)];
lbl.textAlignment = UITextAlignmentLeft;
lbl.font = [UIFont fontWithName:@"Helvetica" size:18.0];
lbl.textColor = [UIColor whiteColor];
lbl.backgroundColor = [UIColor clearColor];
lbl.numberOfLines=0;
UILabel *lbl1 = [[UILabel alloc] initWithFrame:CGRectMake(5, 23, 200, 20)];
lbl1.textAlignment = UITextAlignmentLeft;
lbl1.font = [UIFont fontWithName:@"American Typewriter" size:13.0];
lbl1.textColor = [UIColor whiteColor];
lbl1.backgroundColor = [UIColor clearColor];
lbl1.numberOfLines=0;
UILabel *lbl2 = [[UILabel alloc] initWithFrame:CGRectMake(5,44, 200, 20)];
lbl2.textAlignment = UITextAlignmentLeft;
lbl2.font = [UIFont fontWithName:@"Helvetica-Oblique" size:12.0];
lbl2.textColor = [UIColor whiteColor];
lbl2.backgroundColor = [UIColor clearColor];
lbl2.numberOfLines=0;
if([lblTitle.text isEqualToString:@"Arts & Entertainment"])
{
ArtsClass *arts=[[ArtsClass alloc]init];
arts = [abc.arrSearch objectAtIndex:indexPath.row];
imgUrl = arts.artThumpImg;
lbl.text=arts.artTitle;
lbl1.text=arts.artDesc;
lbl2.text=arts.artDate;
}
else if([lblTitle.text isEqualToString:@"Restaurants"])
{
ResClass *res=[[ResClass alloc]init];
res = [abc.arrSearch objectAtIndex:indexPath.row];
imgUrl = res.resLogoImg;
lbl.text=res.resName;
lbl1.text=res.resType;
lbl2.text=res.resPopularDish;
}
else if([lblTitle.text isEqualToString:@"Bars, Pubs & Clubs"])
{
BarClass *bar=[[BarClass alloc]init];
bar = [abc.arrSearch objectAtIndex:indexPath.row];
imgUrl = bar.barImg;
lbl.text=bar.barTitle;
lbl1.text=bar.barDesc;
lbl2.text=bar.barFacilities;
}
else if([lblTitle.text isEqualToString:@"Film and Cinema"])
{
FilmClass *film=[[FilmClass alloc]init];
film = [abc.arrSearch objectAtIndex:indexPath.row];
imgUrl = film.filmImg;
lbl.text=film.filmName;
lbl1.text=film.filmSynopsis;
lbl2.text=film.filmReleDate;
}
else if([lblTitle.text isEqualToString:@"Live Gigs"])
{
GigsClass *gigs=[[GigsClass alloc]init];
gigs = [abc.arrSearch objectAtIndex:indexPath.row];
imgUrl = gigs.eventThumpImg;
lbl.text=gigs.eventTitle;
lbl1.text=gigs.eventCate;
lbl2.text=[NSString stringWithFormat:@"%@ - %@",gigs.eventStartDate,gigs.eventEndDate];
}
else if([lblTitle.text isEqualToString:@"Shops"])
{
ShopsClass *shops=[[ShopsClass alloc]init];
shops = [abc.arrSearch objectAtIndex:indexPath.row];
imgUrl = shops.shopThumpImg;
lbl.text=shops.shopName;
lbl1.text=shops.shopDesc;
lbl2.text=shops.shopFacilities;
}
NSURL *url = [NSURL URLWithString:imgUrl] ;
// NSLog(@"image link:%@",url);
dispatch_queue_t currQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
dispatch_async(currQueue,^{
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
dispatch_async(dispatch_get_main_queue(), ^{
imgbest.image = [UIImage imageWithData:data];
});
});
[cell addSubview:actSpiner];
[cell addSubview:imgbest];
[cell addSubview:lbl];
[cell addSubview:lbl1];
[cell addSubview:lbl2];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if([lblTitle.text isEqualToString:@"Arts & Entertainment"])
{
abc.subClassTag=@"ARTS";
abc.classTag = @"GALLERYCLASS";
abc.strTitle = @"Arts & Entertainment";
abc.objArt = [abc.arrArts objectAtIndex:indexPath.row];
}
else if([lblTitle.text isEqualToString:@"Restaurants"])
{
abc.subClassTag=@"RES";
abc.classTag = @"GALLERYCLASS";
abc.strTitle = @"Restaurants";
abc.objRest = [abc.arrRes objectAtIndex:indexPath.row];
}
else if([lblTitle.text isEqualToString:@"Bars, Pubs & Clubs"])
{
abc.subClassTag=@"BAR";
abc.classTag = @"GALLERYCLASS";
abc.strTitle = @"Bars, Pubs & Clubs";
abc.objBar = [abc.arrBars objectAtIndex:indexPath.row];
}
else if([lblTitle.text isEqualToString:@"Film and Cinema"])
{
abc.subClassTag=@"FILMS";
abc.classTag = @"PLAYERCLASS";
abc.strTitle = @"Film and Cinema";
abc.objFilm = [abc.arrFilm objectAtIndex:indexPath.row];
}
else if([lblTitle.text isEqualToString:@"Live Gigs"])
{
abc.subClassTag=@"GIGS";
abc.classTag = @"GALLERYCLASS";
abc.strTitle = @"Live Gigs";
abc.objGig = [abc.arrGigs objectAtIndex:indexPath.row];
}
else if([lblTitle.text isEqualToString:@"Shops"])
{
abc.subClassTag=@"SHOPS";
abc.classTag = @"GALLERYCLASS";
abc.strTitle = @"Shops";
abc.objShop = [abc.arrShops objectAtIndex:indexPath.row];
}
if([abc.classTag isEqualToString:@"PLAYERCLASS"])
{
PlayerClass *pl = [[PlayerClass alloc]init];
[self.navigationController pushViewController:pl animated:YES];
}
else if([abc.classTag isEqualToString:@"GALLERYCLASS"])
{
GalaryClass *gc = [[GalaryClass alloc]init];
[self.navigationController pushViewController:gc animated:YES];
}
}
- (void)viewDidUnload
{
scrv = nil;
tableV = nil;
searchBar = nil;
lblTitle = nil;
[super viewDidUnload];
}
-(IBAction)getCategory:(id)sender
{
[searchBar resignFirstResponder];
actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:nil //@"Done"
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet setTag:0];
[actionSheet addSubview:pickerView];
[actionSheet showInView:self.view.superview];
[actionSheet addSubview:pickerToolBar];
[actionSheet showInView:self.view.superview];
[actionSheet setBounds:CGRectMake(0, 0, 320, 430)];
}
-(void)cleartable
{
NSArray * ar=[tableV subviews];
for(int j=0;j<ar.count;j++)
{
NSArray *arr=[[ar objectAtIndex:j]subviews];
for(int i=0;i<arr.count;i++)
{
if([[arr objectAtIndex:i]isKindOfClass:[UILabel class]])
{
[[arr objectAtIndex:i]removeFromSuperview];
}
}
}
}
-(void)showProgress
{
//[searchBar resignFirstResponder];
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
// Set the hud to display with a color
HUD.color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"box4"]];//[UIColor colorWithRed:0.23 green:0.50 blue:0.82 alpha:0.90];
// HUD.opacity =
HUD.delegate = self;
[HUD showWhileExecuting:@selector(download) onTarget:self withObject:nil animated:YES];
}
-(void)download
{
if([NetworkManager checkForNetworkStatus])
{
ParserClass *p =[[ParserClass alloc]init];
NSLog(@"search bar text %@ --- %@",key,lblTitle.text);
if (lblTitle.text==@"Arts & Entertainment")
{
[p search:1 string:key];
}else if(lblTitle.text==@"Restaurants")
{
[p search:5 string:key];
}else if(lblTitle.text==@"Bars, Pubs & Clubs")
{
[p search:4 string:key];
}else if(lblTitle.text==@"Film and Cinema")
{
[p search:2 string:key];
}else if(lblTitle.text==@"Live Gigs")
{
[p search:3 string:key];
}else if(lblTitle.text==@"Shops")
{
[p search:6 string:key];
}
[tableV reloadData];
}
else
{
UIAlertView *alrt = [[UIAlertView alloc]initWithTitle:@"Network Error!" message:@"Please Check your Network connetion.." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alrt show];
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 70;
}
- (void)searchBar:(UISearchBar *)searchBar1 textDidChange:(NSString *)searchText
{
if(![lblTitle.text isEqualToString:@"Select Category"])
{
if(searchBar.text.length > 0)
{
key = searchText;
[self showProgress];
// ParserClass *p =[[ParserClass alloc]init];
// NSLog(@"search bar text %@ --- %@",searchText,lblTitle.text);
// if (lblTitle.text==@"Arts & Entertainment")
// {
// [p search:1 string:searchText];
// }else if(lblTitle.text==@"Restaurants")
// {
// [p search:5 string:searchText];
// }else if(lblTitle.text==@"Bars, Pubs & Clubs")
// {
// [p search:4 string:searchText];
// }else if(lblTitle.text==@"Film and Cinema")
// {
// [p search:2 string:searchText];
// }else if(lblTitle.text==@"Live Gigs")
// {
// [p search:3 string:searchText];
// }else if(lblTitle.text==@"Shops")
// {
// [p search:6 string:searchText];
// }
//
// [tableV reloadData];
}
else
{
UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:nil message:@"Please Give me some Key words..!" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert1 show];
}
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"Please Select any Category..!" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar1
{
[searchBar resignFirstResponder];
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar1
{
[searchBar resignFirstResponder];
}
@end
@实现SearchClass
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
self.tabBarItem.image=[UIImage ImageName:@“搜索”];
UIImageView*navImg=[[UIImageView alloc]initWithImage:[UIImageName:@“i-street”];
self.navigationItem.titleView=navImg;
}
回归自我;
}
-(无效)didReceiveMemoryWarning{[超级didReceiveMemoryWarning];
}
#pragma标记-视图生命周期
-(无效)viewDidLoad
{
[超级视图下载];
self.view.backgroundColor=[UIColor-WithPatternImage:[UIImage ImageName:@“bg1.png”];
abc=(AppDelegate*)[[UIApplication sharedApplication]委托];
//self.navigationController.navigationBar.tintColor=[UIColor blackColor];
//[SearchClass initWithNibName:@”“bundle:nil];
//[SearchClass initWithNibName:@“SearchClass”捆绑包:nil];
arrCate=[[NSMutableArray alloc]initWithObjects:@“艺术与娱乐”、“餐厅”、“酒吧、酒吧和俱乐部”、“电影与电影院”、“现场演出”、“商店”,无];
pickerView=[[UIPickerView alloc]initWithFrame:CGRectMake(0,43320480)];
pickerView.delegate=self;
pickerView.dataSource=self;
[pickerView设置显示选择指示器:是];
pickerToolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0,0320,56)];
pickerToolBar.barStyle=UIBarStyleBlack不透明;
[pickerToolBar sizeToFit];
NSMUTABLEARRY*barItems=[[NSMUTABLEARRY alloc]init];
UIBarButtonItem*flexSpace=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace目标:自我操作:nil];
[barItems addObject:flexSpace];
UIButton*btnDone=[UIButton按钮类型:UIButtonTypeCustom];
[btnDone setFrame:CGRectMake(0,0,60,30)];
[Btnone addTarget:self action:@selector(closeActionSheet)for ControlEvents:UIControlEventTouchUpInside];
[btnDone setBackgroundImage:[UIImage ImageName:@“done.png”]用于状态:UIControlStateNormal];
uibarbuttoneim*dbtn=[[uibarbuttoneim alloc]initWithCustomView:btnDone];
[barItems addObject:dbtn];
[pickerToolBar设置项:barItems动画:是];
}
-(iAction)关闭操作表
{
lblTitle.text=[arrCate objectAtIndex:[pickerView selectedRowInComponent:0];
[actionSheet Dismiss With Clicked Button索引:0动画:是];
}
-(NSInteger)pickerView中组件的编号:(UIPickerView*)pickerView
{
返回1;
}
-(NSString*)pickerView:(UIPickerView*)组件的pickerView标题箭头:(NSInteger)行:(NSInteger)组件{
返回[arrCate objectAtIndex:row];
}
-(NSInteger)pickerView:(UIPickerView*)pickerView行数组件:(NSInteger)组件
{
返回[arrCate count];
}
-(void)pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row不完整项:(NSInteger)组件
{
lblTitle.text=[arrCate objectAtIndex:row];
[abc.arrSearch removeAllObjects];
[表V重新加载数据];
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节{
//NSLog(@“表视图计数seasrch:%d”,[abc.arrSearch计数];
返回[abc.arrSearch count];
}
-(UITableViewCell*)tableView:(UITableView*)aTableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“Cell”;
NSString*imgUrl;
UITableViewCell*单元格=[aTableView出列重用CellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle重用标识符:CellIdentifier];
}
其他的
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle重用标识符:CellIdentifier];
}
如果(indexath.row>0)
{
UIImageView*分隔符=[[UIImageView alloc]initWithImage:[UIImageName:@“line1.png”];
[cell.contentView addSubview:分隔符];
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;
UIImageView*imgbest=[[UIImageView alloc]initWithFrame:CGRectMake(213,4107,64)];
UIActivityIndicatorView*actSpiner=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
actSpiner.center=imgbest.center;
[actSpiner startAnimating];
UILabel*lbl=[[UILabel alloc]initWithFrame:CGRectMake(5,2200,20)];
lbl.textAlignment=UITextAlignmentLeft;
lbl.font=[UIFont fontWithName:@“Helvetica”大小:18.0];
lbl.textColor=[UIColor-whiteColor];
lbl.backgroundColor=[UIColor clearColor];
lbl.numberOfLines=0;
UILabel*lbl1=[[UILabel alloc]initWithFrame:CGRectMake(5,23200,20)];
lbl1.textAlignment=UITextAlignmentLeft;
lbl1.font=[UIFont fontWithName:@“美国打字机”大小:13.0];
lbl1.textColor=[UIColor-whiteColor];
lbl1.backgroundColor=[UIColor clearColor];
lbl1.numberOfLines=0;
UILabel*lbl2=[[UILabel alloc]initWithFrame:CGRectMake(5,44200,
if (lblTitle.text==@"Arts & Entertainment")
if (lblTitle.text isEqualToString:@"Arts & Entertainment")