Index queries in iOS

Source: Internet
Author: User
Tags allkeys

////YCViewController.h//Group Query One////Created by Amin on 14-5-19.//Copyright (c) 2014 Amin. All rights reserved.//#import<UIKit/UIKit.h>@interface Ycviewcontroller:uiviewcontroller<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate>{nsmutabledictionary*Allteams; Nsmutabledictionary*teams; Nsarray*Teamsname; } @property (Nonatomic,retain) nsmutabledictionary*Allteams, @property (nonatomic,retain) nsmutabledictionary*teams, @property (Nonatomic,retain) Nsarray*Teamsname;-(void) Resetsearch; @end
////YCVIEWCONTROLLER.M//Group Query One////Created by Amin on 14-5-19.//Copyright (c) 2014 Amin. All rights reserved.//#import"YCViewController.h"@interface Ycviewcontroller () @end @implementation ycviewcontroller@synthesize allteams,teams,teamsname;#pragma-mark-------------The method used to process the Searchbar delegate to load the display----------------of all grouped data (void) resetsearch{Self.teams=Self.allteams; Nsmutablearray*allkeys=[[Nsmutablearray alloc]init];    [AllKeys addobjectsfromarray:[[teams allkeys]sortedarrayusingselector: @selector (compare:)]]; Self.teamsname=AllKeys; [AllKeys release];}#pragmaThe-mark-------------is used to load the resource file during the initialization of the View----------------(void) viewdidload{[Super Viewdidload]; NSBundle*bundle=[NSBundle Mainbundle]; NSData*data=[ [NSData alloc]initwithcontentsoffile: [Bundle Pathforresource:@"2"OfType:@"jpg"]];//find a resource for NSBundleUIImage *img=[uiimage Imagewithdata:data];//created an Image object that is available[Self.view Setbackgroundcolor:[uicolor colorwithpatternimage:img];//Uicolor Colorwithpatternimage: Method is to convert a picture to a color type to change the background to a given pictureNSString *plistpath = [Bundle Pathforresource:@"Football team Dictionary"OfType:@"plist"]; Nsmutabledictionary*dic=[[Nsmutabledictionary Alloc]initwithcontentsoffile:plistpath]; Self.allteams=dic; Self.teamsname=[dic allkeys]sortedarrayusingselector: @selector (compare:)];    [DIC release];    [Self resetsearch]; }#pragmaThe implementation of-mark-------------for Uitableviewdatasource method---------------#pragma-mark shows several lines under each segment-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{nsstring*name =[Teamsname objectatindex:section]; Nsarray*sectionofdatas=[[Teams Objectforkey:name]sortedarrayusingselector: @selector (compare:)]; return[Sectionofdatas Count];}//Row display.  Implementers should *always* try to reuse cells by setting each cell's reuseidentifier and querying for available reusable Cells with Dequeuereusablecellwithidentifier://Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing Controls)#pragma-mark Displays the display of a row of a column under an index-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{nsuinteger section=[Indexpath section]; Nsuinteger Row=[Indexpath Row]; NSString*name =[Teamsname objectatindex:section]; Nsarray*sectionofdatas=[[Teams Objectforkey:name]sortedarrayusingselector: @selector (compare:)]; StaticNSString *cellidentify=@"cellidentify"; UITableViewCell*cell =[TableView dequeuereusablecellwithidentifier:cellidentify]; if(cell==Nil) {Cell=[[[ UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault Reuseidentifier:cellidentify]autorelease]    ; } Cell.textLabel.text=[Sectionofdatas Objectatindex:row]; returncell;}#pragma-mark shows the number of total points-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView//Default is 1 if not implemented{    return[Teamsname Count];}#pragma-mark displays the name of each segment-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) Section;//fixed font style. Use Custom view (UILabel) If you want something different{nsstring*name =[Teamsname objectatindex:section]; returnname;}#pragma-mark displays the flag for each segment end-(NSString *) TableView: (UITableView *) TableView titleforfooterinsection: (nsinteger) section{return @"";}//Index-(Nsarray *) Sectionindextitlesfortableview: (UITableView *) TableView//return list of sections titles to display in section index view (e.g. "ABCD ... z# "){        returnTeamsname;}#pragmaThe implementation of-mark-------------for Uitableviewdelegate method---------------#pragma-mark displays a row value for the selected index of the user action//called after the user changes the selection.- (void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{nsuinteger section=[Indexpath section]; Nsuinteger Row=[Indexpath Row]; NSString*name =[Teamsname objectatindex:section]; Nsarray*sectionofdatas=[[Teams Objectforkey:name]sortedarrayusingselector: @selector (compare:)]; NSString*message=[[nsstring Alloc]initwithformat:@"you chose the%@%@ team.", Name,[sectionofdatas Objectatindex:row]]; Uialertview*view =[[uialertview Alloc]initwithtitle:@"your favorite team."Message:messageDelegate: Self Cancelbuttontitle:@"Determine"Otherbuttontitles:nil];    [TableView Deselectrowatindexpath:indexpath Animated:yes];    [View show];    [View release]; [Message release];}#pragmaThe implementation of-mark-------------for Searchbardelegate method---------------#pragma-mark search for this group by group name-(void) Searchbar: (Uisearchbar *) Searchbar textdidchange: (NSString *) SearchText//called when text changes (including clear){        if([SearchText isequaltostring:@""]) {[Self resetsearch]; return; } nsmutabledictionary*dict=[[Nsmutabledictionary alloc]init];  for(NSString *keyinchself.teams) {Nsmutablearray*array=[Allteams Objectforkey:key]; Nsmutablearray*newteams=[[Nsmutablearray alloc]init];  for(NSString *teamnameinchArray) {            if([Teamname Rangeofstring:searchtext options:nscaseinsensitivesearch].location!=nsnotfound)            {[Newteams addobject:teamname]; }        }        if([Newteams count]>0) {[Dict setobject:newteams forkey:key];    } [Newteams release]; } self.teamsname=[[Dict allkeys]sortedarrayusingselector: @selector (compare:)]; Self.teams=dict; [Dict release];}-(void) searchbarcancelbuttonclicked: (Uisearchbar *) searchbar{[self resetsearch];}//------------------------------------------------------------------------------------------------------///- (void) didreceivememorywarning{[Super didreceivememorywarning]; }#pragma-mark-------------the release processing----------------of the memory space used to process the property (void) viewdidunload{Self.teamsname=Nil; Self.teams=Nil; Self.allteams=Nil;}- (void) dealloc{[teams release];    [Teamsname release];    [Allteams release]; [Super Dealloc];} @end

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.