Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何添加搜索栏?_Iphone_Search_Uitableview_Navigationcontroller - Fatal编程技术网

Iphone 如何添加搜索栏?

Iphone 如何添加搜索栏?,iphone,search,uitableview,navigationcontroller,Iphone,Search,Uitableview,Navigationcontroller,我是xcode新手,也搜索过教程,但大多数教程只提供如何使用代码并进行搜索,我已经有了一个应用程序,希望在其中实现一个搜索栏。我想知道是否有人能给我指出正确的方向?这是 #import "RootViewController.h" #import "AppDelegate.h" #import "DetailViewController.h" @implementation RootViewController #pragma mark - #pragma mark Synthesizers

我是xcode新手,也搜索过教程,但大多数教程只提供如何使用代码并进行搜索,我已经有了一个应用程序,希望在其中实现一个搜索栏。我想知道是否有人能给我指出正确的方向?这是

#import "RootViewController.h"
#import "AppDelegate.h"
#import "DetailViewController.h"

@implementation RootViewController

#pragma mark -
#pragma mark Synthesizers

@synthesize table;
@synthesize sitesList;
@synthesize imagesList;
@synthesize descArray;
@synthesize bannerImages;
@synthesize childController;

#pragma mark -
#pragma mark View methods

- (void)viewDidLoad {

    NSArray *sites = [[NSArray alloc] initWithObjects:
                      @"#1 or NUMBER ONE",
                      @"#2 or NUMBER TWO",
                      @"#3 or NUMBER THREE",
                      @"1 or ONE",
                      @"10-100,10-1,10-200,10-2,10-4 and 20",
                      @"1000H PAPER",
                      @"129 or HEAVY FROST",
                      @"18% GRAY or GREY CARD",
                      @"180 DEGREE RULE",
                      @"2 or TWO",
                      @"214 or FULL TOUGH SPUN",
                      @"215 or HALF TOUGH SPUN",
                      @"216 or FULL WHITE DIFFUSION",
                      @"220 or WHITE FROST",
                      @"229 or QUARTER TOUGH SPUN",
                      @"250 or HALF WHITE DIFFUSION",
                      @"251 or QUARTER WHITE DIFFUSION",
                      @"252 or EIGHTH WHITE DIFFUSION",
                      @"253 or FULL HAMPSHIRE",
                      @"254 or NEW HAMPSHIRE",
                      @"255 or HOLLYWOOD FROST",
                      @"256 or HALF HAMPSHIRE FROST",
                      @"257 or QUARTER HAMPSHIRE FROST",
                      @"258 or EIGHTH HAMPSHIRE FROST",
                      @"3200K or TUNGSTEN",
                      nil];
    self.sitesList = sites;

    [sites release];



    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Descriptions" ofType:@"plist"];

    NSArray *desc = [[NSArray alloc] initWithContentsOfFile:filePath];

    self.descArray = desc;

    [desc release];



    UIImage *texas = [UIImage imageNamed:@"1andtexas.jpg"];
    UIImage *cali = [UIImage imageNamed:@"2andcalifornia.jpg"];
    UIImage *ny = [UIImage imageNamed:@"3andnewyork.jpg"];
    UIImage *tmark = [UIImage imageNamed:@"1Tmark.jpg"];
    UIImage *walkie = [UIImage imageNamed:@"Walkietalkie.jpg"];
    UIImage *onekh = [UIImage imageNamed:@"Tracingpaper.jpg"];
    UIImage *onetwonine = [UIImage imageNamed:@"diffusion.jpg"];
    UIImage *greycard = [UIImage imageNamed:@"Greycard.jpg"];
    UIImage *oneeighty = [UIImage imageNamed:@"Oneeighty.jpg"];
    UIImage *two = [UIImage imageNamed:@"Two.jpg"];
    UIImage *twofourteen = [UIImage imageNamed:@"Diffusion.jpg"];
    UIImage *twofifteen = [UIImage imageNamed:@"Diffusion.jpg"];
    UIImage *twosixteen = [UIImage imageNamed:@"Diffusion.jpg"];
    UIImage *twotwenty = [UIImage imageNamed:@"Diffusion.jpg"];
    UIImage *twotwentynine = [UIImage imageNamed:@"Diffusion.jpg"];
    UIImage *twofifty = [UIImage imageNamed:@"Diffusion.jpg"];
    UIImage *twofiftyone = [UIImage imageNamed:@"Diffusion.jpg"];
    UIImage *twofiftytwo = [UIImage imageNamed:@"Diffusion.jpg"];
    UIImage *twofiftythree = [UIImage imageNamed:@"Diffusion.jpg"];
    UIImage *twofiftyfour = [UIImage imageNamed:@"Diffusion.jpg"];
    UIImage *twofiftyfive = [UIImage imageNamed:@"Diffusion.jpg"];
    UIImage *twofiftysix = [UIImage imageNamed:@"Diffusion.jpg"];
    UIImage *twofiftyseven = [UIImage imageNamed:@"Diffusion.jpg"];
    UIImage *twofiftyeight = [UIImage imageNamed:@"Diffusion.jpg"];
    UIImage *thirtytwohk = [UIImage imageNamed:@"3200k.jpg"];

    NSArray *banners = [[NSArray alloc] initWithObjects:texas,
                        cali,
                        ny,
                        tmark,
                        walkie,
                        onekh,
                        onetwonine,
                        greycard,
                        oneeighty,
                        two,
                        twofourteen,
                        twofifteen,
                        twosixteen,
                        twotwenty,
                        twotwentynine,
                        twofifty,
                        twofiftyone,
                        twofiftytwo,
                        twofiftythree,
                        twofiftyfour,
                        twofiftyfive,
                        twofiftysix,
                        twofiftyseven,
                        twofiftyeight,
                        thirtytwohk,
                        nil];

    self.bannerImages = banners;

    [banners release];

    [app release];
    [creat release];
    [free release];
    [net release];
    [rock release];
    [tuts release];
    [work release];
     */

    [super viewDidLoad];    
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Support all the orientations except for PortraitUpsideDown
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

#pragma mark -
#pragma mark Table view datasource methods

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

// A-Z
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {

    NSMutableArray *toBeReturned = [[NSMutableArray alloc]init];
    for(char c = 'A'; c <= 'Z'; c++) [toBeReturned addObject:[NSString stringWithFormat:@"%c",c]];
    return toBeReturned;
}

-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
    return [sitesList count];
}

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Set the title for the cell
    cell.textLabel.text = [sitesList objectAtIndex:indexPath.row];

    cell.imageView.image = [imagesList objectAtIndex:indexPath.row];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    // Return the cell
    return cell;
}


#pragma mark -
#pragma mark Table view delegate methods

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50; // Default height for the cell is 44 px;
}

-(NSString *) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    return @"Flm Set Decipher";
}

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    DetailViewController *detailVC = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];

    detailVC.banner = [bannerImages objectAtIndex:indexPath.row];

    detailVC.description = [descArray objectAtIndex:indexPath.row];

    detailVC.title = [sitesList objectAtIndex:indexPath.row];

    self.childController = detailVC;

    [delegate.navigationController pushViewController:childController animated:YES];

    [detailVC release];

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


#pragma mark -
#pragma mark Memory Management

- (void)didReceiveMemoryWarning {
    NSLog(@"Memory warning!");
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
    self.table = nil;
    self.sitesList = nil;
    self.imagesList = nil;
    self.descArray = nil;
    self.bannerImages = nil;
    self.childController = nil;
    [super viewDidUnload];
}

- (void)dealloc {
    [table release];
    [sitesList release];
    [imagesList release];
    [descArray release];
    [bannerImages release];
    [childController release];
    [super dealloc];
}

@end
#导入“RootViewController.h”
#导入“AppDelegate.h”
#导入“DetailViewController.h”
@RootViewController的实现
#布拉格标记-
#布拉格符号合成器
@综合表;
@综合站点列表;
@合成图像列表;
@合成天线阵;
@综合图像;
@综合控制器;
#布拉格标记-
#pragma标记视图方法
-(无效)viewDidLoad{
NSArray*站点=[[NSArray alloc]initWithObjects:
@“#1或1号”,
@“#2或2号”,
@“三号还是三号”,
@“1或1”,
@“10-100、10-1、10-200、10-2、10-4和20”,
@“1000小时纸张”,
@“129或重霜”,
@“18%灰色或灰色卡片”,
@“180度规则”,
@“两个或两个”,
@“214或全硬纺”,
@“215或半强力旋转”,
@“216或全白色扩散”,
@“220或白霜”,
@“229或四分之一强力旋转”,
@“250或半白色扩散”,
@“251或四分之一白色扩散”,
@“252或第八次白色扩散”,
@“253或全汉普郡”,
@“254或新罕布什尔州”,
@“255或好莱坞霜”,
@“256或半汉普郡霜”,
@“257或四分之一汉普郡霜冻”,
@“258或第八汉普郡霜冻”,
@“3200K或钨”,
零];
self.sitesList=站点;
[网站发布];
NSString*文件路径=[[NSBundle mainBundle]pathForResource:@“Descriptions”类型:@“plist”];
NSArray*desc=[[NSArray alloc]initWithContentsOfFile:filePath];
self.descArray=desc;
[描述释放];
UIImage*texas=[UIImage ImageName:@“1和texas.jpg”];
UIImage*cali=[UIImage ImageName:@“2andcalifornia.jpg”];
UIImage*ny=[UIImage ImageName:@“3andnewyork.jpg”];
UIImage*tmark=[UIImage ImageName:@“1Tmark.jpg”];
UIImage*walkie=[UIImage ImageName:@“Walkietalkie.jpg]”;
UIImage*onekh=[UIImage imagename:@“Tracingpaper.jpg”];
UIImage*onetwonine=[UIImage-imagename:@“diffusion.jpg]”;
UIImage*greycard=[UIImage ImageName:@“greycard.jpg”];
UIImage*OneEarth=[UIImage ImageName:@“OneEarth.jpg”];
UIImage*two=[UIImage ImageName:@“two.jpg”];
UIImage*TwoTeven=[UIImage ImageName:@“Diffusion.jpg”];
UIImage*two十五=[UIImage imagename:@“Diffusion.jpg”];
UIImage*twoElexture=[UIImage ImageName:@“Diffusion.jpg]”;
UIImage*TwoTown=[UIImage ImageName:@“Diffusion.jpg]”;
UIImage*twotwentynine=[UIImage ImageName:@“Diffusion.jpg]”;
UIImage*Twowever=[UIImage ImageName:@“Diffusion.jpg”];
UIImage*twofiftyone=[UIImage ImageName:@“Diffusion.jpg]”;
UIImage*twofiftytwo=[UIImage ImageName:@“Diffusion.jpg]”;
UIImage*twofiftythree=[UIImage ImageName:@“Diffusion.jpg]”;
UIImage*twofiftyfour=[UIImage ImageName:@“Diffusion.jpg]”;
UIImage*twofiftyfive=[UIImage ImageName:@“Diffusion.jpg]”;
UIImage*twofiftysix=[UIImage ImageName:@“Diffusion.jpg]”;
UIImage*twofiftyseven=[UIImage ImageName:@“Diffusion.jpg]”;
UIImage*twofiftyeight=[UIImage ImageName:@“Diffusion.jpg]”;
UIImage*thirtytwohk=[UIImage ImageName:@“3200k.jpg”];
NSArray*横幅=[[NSArray alloc]initWithObjects:texas,
卡利,
纽约,
tmark,
随身听,
奥涅克,
奥特沃宁,
格雷卡德,
一百八十,
二
214,
二一五,,
二一六,,
二二十,
二十九,
二五,,
二五一,,
二五二,,
二五三,,
二五四,
二五五,,
二五六,
257,
258,
香港三十二号,
零];
self.bannerImages=横幅;
[发布横幅];
[应用程序发布];
[创建发布];
[自由释放];
[净释放];
[岩石释放];
[图坦卡蒙释放];
[工作释放];
*/
[超级视图下载];
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation{
//支持所有方向,但上下方向除外
返回(interfaceOrientation!=UIInterfaceOrientation肖像向上向下);
}
#布拉格标记-
#pragma标记表视图数据源方法
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
返回1;
}
//A-Z
-(NSArray*)sectionIndexTitlesForTableView:(UITableView*)表格视图{
NSMUTABLEARRY*TOBERETURN=[[NSMUTABLEARRY alloc]init];

对于(char c='A';c这就是你要做的!遵循本教程

或者,这里有一个苹果的例子:


你应该考虑在你需要的时候加载资源(特别是你的横幅)。所有的预加载将占用很多RAM,特别是因为你多次加载相同的图像。