I have a button that saves cell's data upon ButtonClick
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.checkbox = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect checkboxRect = CGRectMake(135, 150, 36, 36);
[self.checkbox setFrame:checkboxRect];
[self.checkbox setImage:[UIImage imageNamed:#"unselected#2x.png"]forState:UIControlStateNormal];
[self.checkbox setImage:[UIImage imageNamed:#"selected#2x.png"] forState:UIControlStateSelected];
[self.checkbox addTarget:self action:#selector(checkboxClicked:) forControlEvents:UIControlEventTouchUpInside];
self.accessoryView = self.checkbox;
array = [NSMutableArray array];
}
return self;
}
-(void)checkboxClicked:(UIButton *)sender{
sender.selected = !sender.selected;
UITableViewCell *cell = (AddressBookCell *)sender.superview;
if(sender.selected){
[array addObject:cell];
}
}
and i use that array in my other class, but it keeps giving me empty arrays;
this is my other class, it gives me a log of Zero.
-(void)textMessage{
/*UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Error" message:#"Not Implmeneted Yet" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles: nil];
[alert show];
[alert release];*/
AddressBookCell *names = [[AddressBookCell alloc]init];
NSLog(#"%d",[[names array]count]);
}
![1] http://min.us/m2GMsoRap
I need a way to store data upon button click and transfer it to my other classes.
EDIT## full code
#import "AddressBookCell.h"
#implementation AddressBookCell
#synthesize checkbox;
#synthesize array;
#synthesize addressController;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.checkbox = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect checkboxRect = CGRectMake(135, 150, 36, 36);
[self.checkbox setFrame:checkboxRect];
[self.checkbox setImage:[UIImage imageNamed:#"unselected#2x.png"]forState:UIControlStateNormal];
[self.checkbox setImage:[UIImage imageNamed:#"selected#2x.png"] forState:UIControlStateSelected];
[self.checkbox addTarget:self action:#selector(checkboxClicked:) forControlEvents:UIControlEventTouchUpInside];
self.accessoryView = self.checkbox;
array = [[NSMutableArray alloc]init];
}
return self;
}
-(void)checkboxClicked:(UIButton *)sender{
sender.selected = !sender.selected;
UITableViewCell *cell = (AddressBookCell *)sender.superview;
NSLog(#"%d'",cell.tag);
if(sender.selected){
[array addObject:cell];
}else{
if([array containsObject:cell]){
[array removeObject:cell];
}
NSLog(#"%d", [array count]);
}
}
and now my other class
-(void)setUpContacts{
NSDictionary *alphabet = [[NSDictionary alloc]initWithObjectsAndKeys:[NSNumber numberWithInt:0],#"A",[NSNumber numberWithInt:1],#"B",[NSNumber numberWithInt:2],#"C",[NSNumber numberWithInt:3],#"D",[NSNumber numberWithInt:4],#"E",[NSNumber numberWithInt:5],#"F",[NSNumber numberWithInt:6],#"G",[NSNumber numberWithInt:7],#"H",[NSNumber numberWithInt:8],#"I",[NSNumber numberWithInt:9],#"J",[NSNumber numberWithInt:10],#"K",[NSNumber numberWithInt:11],#"L",[NSNumber numberWithInt:12],#"M",[NSNumber numberWithInt:13],#"N",[NSNumber numberWithInt:14],#"O",[NSNumber numberWithInt:15],#"P",[NSNumber numberWithInt:16],#"Q",[NSNumber numberWithInt:17],#"R",[NSNumber numberWithInt:18],#"S",[NSNumber numberWithInt:19],#"T",[NSNumber numberWithInt:20],#"U",[NSNumber numberWithInt:21],#"V",[NSNumber numberWithInt:22],#"W",[NSNumber numberWithInt:23],#"X",[NSNumber numberWithInt:24],#"Y",[NSNumber numberWithInt:25],#"Z", nil];
NSMutableArray *tempArray = [[NSMutableArray alloc]init];
for(int i = 0; i<=27; i++){
[tempArray addObject:[NSNull null]];
}
Contacts *contact = [[Contacts alloc]init];
contactNumbers = [contact phoneNumbers];
for (NSDictionary* info in contactNumbers) {
firstLetter = [info objectForKey:#"lastName"];
int index = 27;
if([firstLetter length] > 0){
firstLetter =[NSString stringWithFormat:#"%C",[firstLetter characterAtIndex:0]];
firstLetter= [firstLetter capitalizedString];
if([alphabet objectForKey:firstLetter]){
NSNumber *t = [alphabet valueForKey:firstLetter];
index = [t intValue] + 1;
}
}
if([tempArray objectAtIndex:index] == [NSNull null]){
[tempArray insertObject:[NSMutableArray array] atIndex:index];
}
[[tempArray objectAtIndex:index] addObject:info];
}
[alphabet release];
NSArray *alphabet2 = [[NSArray alloc]initWithObjects:#"A",#"B",#"C",#"D",#"E",#"F",#"G",#"H",#"I",#"J",#"K",#"L",#"M",#"N",#"O",#"P",#"Q",#"R",#"S",#"T",#"U",#"V",#"W",#"X",#"Y",#"Z", nil];
NSMutableArray *tempArray2 = [[NSMutableArray alloc]init];
NSMutableArray *titleTemp = [[NSMutableArray alloc]init];
int c = 0;
for(int i = 0; i<=27; i++){
if([tempArray objectAtIndex:i] != [NSNull null]){
if(i == 0){
[titleTemp insertObject:#"Suggested" atIndex:c];
}else if(i == 27){
[titleTemp insertObject:#"Others" atIndex:c];
}else{
int loc = i -1;
[titleTemp insertObject:[alphabet2 objectAtIndex:loc] atIndex:c];
}
[tempArray2 insertObject:[tempArray objectAtIndex:i] atIndex:c];
c++;
}
}
[alphabet2 release];
[tempArray release];
letterArray = tempArray2;
titlePointer = titleTemp;
}
-(void)textMessage{
/*UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Error" message:#"Not Implmeneted Yet" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles: nil];
[alert show];
[alert release];*/
AddressBookCell *names = [[AddressBookCell alloc]init];
savedArray = [NSArray arrayWithArray:[names array]];
NSLog(#"%#",savedArray);
}
- (void)viewDidLoad{
[super viewDidLoad];
[self setUpContacts];
indexPaths = [[NSMutableDictionary alloc]init];
//suggestedPeople = [[NSArray alloc]initWithObjects:#"User1",#"User2",#"User3",#"User4", nil];
//set up the tableView
self.myTableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
self.myTableView.delegate = self;
self.myTableView.dataSource = self;
self.title = #"Select Friends";
self.myTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:myTableView];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:#"Text"style:UIBarButtonItemStylePlain target:self action:#selector(textMessage)];
//testing section
}
Of course it's empty, you alloc/init'd a new instance of AdressBookCell in your other class, so it doesn't have anything in its array. You need a property in your other class that points to the instance of your first class where you fill your array, and then you can use [pointerToFirstClass array] to get at that array.
It looks like you are using manual memory management. If not, you need to specify.
In the case that you are, when you create the array with the line [NSMutableArray array], you are creating an autoreleased object that will be released before your other class tries to access it.
You'll need to retain it at the point you create it, and release it in your dealloc. If you change [NSMutableArray array] to [[NSMutableArray array] retain] and add an [array release] line to your dealloc the array won't disappear on you until you release the owning object.
you haven't included enough info to tell what is going on, but I can guess...
a log of zero could mean an empty array, or more likely a nil array... try this:
AddressBookCell *names = [[AddressBookCell alloc]init];
NSLog(#"%#",[names array]);
Related
I created iOS(5.0) application in that I have search Bar, which is used to search the content in server side, while passing keyword entered into search bar the list of content parsed from the xml and shown in Table View,
its working fine in Emulator,.but in device (ipad2 & iphone4s) its not showing table of content were searched.
pls let me know what am making wrong..
Thanks in advance,.
murali.
This is mySearchClass.h
#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
//======================
This is my SearchClass.m
#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
Thanks for ur Reply,.
Murali.
wrong string comparison
if (lblTitle.text==#"Arts & Entertainment")
it should be like this - try this it must work & let me know.
if (lblTitle.text isEqualToString:#"Arts & Entertainment")
I am also having some issues in my search class, i am using JSON url.
Where is the Parsing URL, what are the fields in the xml.
Check your parsing url in ur local browser by manual append method using query string ,working or not.
check by trace path, use console log for print the URL.
Check if u are using localhost url in ur program somewhere else.
Check your delegate for search class.
use this link for your reference.
https://iphonedevsdk.com/forum/iphone-sdk-development/50468-xml-table-view-searchbar.html
I am having some difficulty figuring out the best way to get my uitextfields to not be hidden when the keyboard popsup. Right now i have a UIView that contains a uitableview subview and button.
*The tableview that is inside the uiview is actually a uiviewcontroller with a programatically created tableivew, so it is not controlled by a uitableviewcontroller.
I have done research and i think i would need a scrollview then add the view to the scrollview and work on some scrolling when a specific textfield is selected and is hidden with the keyboard up scroll it up.
Is this a good approach ?
UPDATE:
I have two seperate Viewcontrollers. For-example let say MainViewcontroller and SecondViewcontroller. The secondviewcontroller has a uitableview in it. The cells inside of the tableview have textboxes which store user information(like a form). Then what i did was created an object of secondviewcontroller inside of mainviewcontroller. I did this becuause i need to have a "Next Button" at the bottom of the view. When I select a field where it would be located underneith the keyboard when it pops up i would like to have it scroll up and when closed it will go down. I had to use an object of uitableview because the Mainviewcontroller class would be way to big.(Please correct me if i am wrong). Thanks for the reply.
Here is a screenshot of what i am trying to do...
FUll UIView: http://postimage.org/image/puzdwpj3t/
With Keyboard open: http://postimage.org/image/g5nkwzwpd/
//Here is some code:
1. The first class here is for instance SecondViewcontroller.
2. The second section of code is for instance the mainviewcontroller, which creates an object of secondviewcontroller.
The below uiviewcontroller will create a table with 3 sections. Each cell has a textfield(except the middle, it is a button which pulls up a uipickerview). This is not a full class i only took the areas where the table is created.
-(void)viewDidLoad{
[super viewDidLoad];
// scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 300, 500)];
// scrollview.pagingEnabled = YES;
//
// //[scrollview addSubview:self.view];
// [self.view addSubview:scrollview];
table.scrollEnabled = YES;
dataArray = [[NSMutableArray alloc] init];
titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 290, 30)];
//dropper
titleField = [[UITextField alloc] initWithFrame:CGRectMake(10, 2, 300, 30)];
titleField.layer.cornerRadius = 8;
titleField.backgroundColor = [UIColor clearColor];
NSArray *firstItemsArray = [[NSArray alloc] initWithObjects:#"1",#"2", nil];
NSDictionary *firstItemsArrayDict = [NSDictionary dictionaryWithObject:firstItemsArray forKey:#"data"];
[dataArray addObject:firstItemsArrayDict];
//Second section dat
NSArray *secondItemsArray = [[NSArray alloc] initWithObjects:#"1", nil];
NSDictionary *secondItemsArrayDict = [NSDictionary dictionaryWithObject:secondItemsArray forKey:#"data"];
[dataArray addObject:secondItemsArrayDict];
NSArray *thirdItemsArray = [[NSArray alloc] initWithObjects:#"1",#"2",#"3", nil];
NSDictionary *thirdItemsArrayDict = [NSDictionary dictionaryWithObject:thirdItemsArray forKey:#"data"];
[dataArray addObject:thirdItemsArrayDict];
NSLog(#"the dataArray%#",dataArray);
if([self connectedToNetwork]){
dispatch_async(kBgQueue, ^{
//build the url of strings
FULLURL = [SERVERNAME stringByAppendingFormat:TitleLink];
//create the url
NSURL *url = [[NSURL alloc] initWithString:FULLURL];
//NSLog(#"here title url%#",url);
//get the data from the url
NSData* data = [NSData dataWithContentsOfURL: url];
//NSLog(#"here%#",data);
//get the data from the url
[self performSelectorOnMainThread:#selector(fetchedData:) withObject:data waitUntilDone:YES];
// NSLog(#"titleid:%#",TITLEID);
// NSLog(#"title categories:%#",titlecategories);
});
[table setBounces:NO];
}else{
dispatch_async(dispatch_get_main_queue(), ^ {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Please Check your internet connection"
message:#"Enable your internet connection"
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
});
}
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return [dataArray count];
}
-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
//Number of rows it should expect should be based on the section
NSDictionary *dictionary = [dataArray objectAtIndex:section];
NSArray *array = [dictionary objectForKey:#"data"];
return [array count];
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 1){
cell.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageNamed:#"longdropper300.png"]];
}
else{
cell.backgroundColor = [UIColor whiteColor];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
textField = [[UITextField alloc] initWithFrame:CGRectMake(15, 10, 290, 30)];
static NSString *cellValue = #"Cell";
UITableViewCell *cell =nil;
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellValue];
}
cell.selectionStyle = UITableViewCellSelectionStyleGray;
if ([indexPath section] == 0) {
//cellValue=[items objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle= UITableViewCellSelectionStyleNone;
//textField.tag = 1;
textField.adjustsFontSizeToFitWidth = YES;
textField.textColor = [UIColor blackColor];
if(indexPath.section == 0){
//textfield for email
if ([indexPath row] == 0) {
textField.tag = 1;
textField.text = EMAIL;
textField.textColor= [UIColor blackColor];
textField.placeholder = #"Email: example#gmail.com";
textField.keyboardType = UIKeyboardTypeEmailAddress;
textField.returnKeyType = UIReturnKeyNext;
}
//textfield for phone number
else {
textField.tag = 2;
if ([PHONENUMBER isEqual: [NSNull null]] && PHONENUMBER == nil && PHONENUMBER == NULL && [PHONENUMBER isEqual: #""]){
NSLog(#"phone is empty%#",PHONENUMBER);
//[PHONENUMBER isEqual:#"frank"];
}else{
NSLog(#"phone is not empty%#",PHONENUMBER);
textField.text = PHONENUMBER;
}
textField.placeholder = #"Phone: xxx-xxx-xxxx";
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.secureTextEntry = NO;
}
textField.backgroundColor = [UIColor whiteColor];
textField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
textField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
textField.textAlignment = UITextAlignmentLeft;
textField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
[textField setEnabled: YES];
textField.delegate = self;
[cell addSubview:textField];
}
}
if(indexPath.section == 1){
[titleField setTextColor:[UIColor whiteColor]];
titleField.tag = 3;
titleField.placeholder = #"Select Contact Title";
titleField.returnKeyType = UIReturnKeyNext;
//titleField == textField.tag = 3;
if ([TITLENAME isEqual: [NSNull null]]){
NSLog(#"titlename is empty%#",TITLENAME);
}else{
NSLog(#"titlename is not empty%#",TITLENAME);
titleField.text = TITLENAME;
}
titleField.keyboardType = UIKeyboardTypeDefault;
titleField.returnKeyType = UIReturnKeyDone;
titleField.secureTextEntry = NO;
titleField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
titleField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
titleField.textAlignment = UITextAlignmentCenter;
titleField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
[titleField setEnabled: NO];
titleField.delegate = self;
[cell addSubview:titleField];
NSLog(#"here is the titlename%#",TITLENAME);
}
if(indexPath.section == 2){
if ([indexPath row] == 0) {
textField.tag = 4;
textField.placeholder = #"First Name";
cell.selectionStyle= UITableViewCellSelectionStyleNone;
if ([FIRSTNAME isEqual: [NSNull null]]){
NSLog(#"firstname is empty%#",FIRSTNAME);
textField.text = #"";
}else{
textField.text = FIRSTNAME;
}
textField.keyboardType = UIKeyboardTypeEmailAddress;
textField.returnKeyType = UIReturnKeyNext;
}
if([indexPath row] == 1){
textField.tag = 5;
textField.placeholder = #"Last Name";
if ([LASTNAME isEqual: [NSNull null]]){
NSLog(#"lastname is empty%#",LASTNAME);
textField.text = #"";
}else{
textField.text = LASTNAME;
}
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyNext;
//textField.secureTextEntry = NO;
}
if([indexPath row] == 2){
textField.tag = 6;
textField.placeholder = #"Company";
if ([COMPANY isEqual: [NSNull null]]){
NSLog(#"company is empty%#",COMPANY);
textField.text = #"";
}
else{
textField.text = COMPANY;
}
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.secureTextEntry = NO;
}
//]textField.backgroundColor = [UIColor whiteColor];
textField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
textField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
textField.textAlignment = UITextAlignmentLeft;
textField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
[textField setEnabled: YES];
textField.delegate = self;
[cell addSubview:textField];
}
return cell;
}
//Change the Height of title cell drop down
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
if (indexPath.section == 1) {
if (indexPath.row == 0) {
return 30;
}
}
return 45;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
if(([textField tag] == 1)){
NSString *emailRegEx = #"[A-Z0-9a-z._%+-]+#[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:#"SELF MATCHES %#", emailRegEx];
//Valid email address
if ([emailTest evaluateWithObject:textField.text] == YES)
{
EMAIL = [textField.text copy];
NSLog(#"here is the email%#",EMAIL);
}
else
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Bad Email"
message: #"Please Re-enter the email address with a valid email"
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
textField.text = nil;
NSLog(#"email not in proper format");
}
}
if(([textField tag] == 2)){
NSString *phoneRegex = #"[235689][0-9]{6}([0-9]{3})?";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:#"SELF MATCHES %#", phoneRegex];
//valid email address
if ([phoneTest evaluateWithObject:textField.text] == YES)
{
PHONENUMBER = [textField.text copy];
NSLog(#"here is the phone number %#",PHONENUMBER);
}
else
{
NSLog(#"Phone Number Invalid");
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"xxx-xxx-xxxx"
message: #"Please enter a valid phone number"
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
textField.text = nil;
}
}
if(([textField tag] == 4)){
FIRSTNAME = [textField.text copy];
NSLog(#"here is the firstName%#",FIRSTNAME);
}
if(([textField tag] == 5)){
LASTNAME = [textField.text copy];
NSLog(#"here is the Last Name%#",LASTNAME);
}
if(([textField tag] == 6)){
COMPANY = [textField.text copy];
NSLog(#"here is the Company%#",COMPANY);
}
return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField*)textField;
{
NSInteger nextTag = textField.tag + 1;
// Try to find next responder
UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
if (nextResponder) {
// Found next responder, so set it.
[nextResponder becomeFirstResponder];
} else {
// Not found, so remove keyboard.
[textField resignFirstResponder];
}
return NO; // We do not want UITextField to insert line-breaks.
}
Main View Controller
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)addMyButton{ // Method for creating button, with background image and other properties
loginButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
loginButton.frame = CGRectMake(10.0,130.0, 300.0, 40.0);
[loginButton setTitle:#"Login" forState:UIControlStateNormal];
loginButton.backgroundColor = [UIColor clearColor];
[loginButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal ];
UIImage *buttonImageNormal = [UIImage imageNamed:#"blueButton.png"];
UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[loginButton setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal];
UIImage *buttonImagePressed = [UIImage imageNamed:#"whiteButton.png"];
UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[loginButton setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted];
[self.view addSubview:loginButton];
[loginButton addTarget: self
action: #selector(loginButtonClicked:)
forControlEvents: UIControlEventTouchUpInside];
}
//Change the View and send the information to the servlet once login is clicked.
- (void)loginButtonClicked: (id)sender{
loginButton.enabled = NO;
activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(20, 60, 20, 20)];
UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
[self navigationItem].rightBarButtonItem = barButton;
[activityIndicator startAnimating];
[passwordTF resignFirstResponder];
//start new thread
//dispatch_async(kBgQueue, ^{
NSLog(#"Username:%#",USERNAME);
NSLog(#"Password:%#",PASSWORD);
NSLog(#"COMPANYID: %#", COMPANYID);
//NSLog(#"LOGINID: %#", LOGINID);
if((USERNAME == NULL) || (USERNAME == nil) || ([USERNAME isEqualToString:#""])){
//NSLog(#"null password or usernaem");
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Username or password not found"
message:#"please try again"
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[activityIndicator stopAnimating];
// MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
// [self.navigationController pushViewController:SenderInfoViews animated:NO];
}else if((PASSWORD == NULL) || (PASSWORD == nil) || ([PASSWORD isEqualToString:#""])){
//NSLog(#"null password or usernaem");
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Username or password not found"
message:#"please try again"
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[activityIndicator stopAnimating];
// MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
// [self.navigationController pushViewController:SenderInfoViews animated:NO];
}else{
//NSLog(#"all good");
NSLog(#"Login button clicked, load the next view and check for password");
NSLog(#"full the url%#",FULLURL);
//build the url of strings
FULLURL = ******
if([self connectedToNetwork])
{
dispatch_queue_t downloadQueue = dispatch_queue_create("data loader", NULL);
dispatch_async(downloadQueue, ^{
//create the url
NSURL *url = [[NSURL alloc] initWithString:FULLURL];
NSLog(#"here%#",url);
//get the data from the url
NSData* data = [NSData dataWithContentsOfURL: url];
NSLog(#"here%#",data);
NSLog(#"here that data%#",data);
if(data != nil){
//
//get the data from the url
[self performSelectorOnMainThread:#selector(fetchedData:) withObject:data waitUntilDone:YES];
//
NSLog(#"hello Username:%#",USERNAME);
NSLog(#"Password:%#",PASSWORD);
NSLog(#"h4llo COMPANYID: %#", COMPANYID);
NSLog(#"LOGINID: %#", LOGINID);
//
// // [self performSelectorOnMainThread:#selector(checkLogin:) withObject:LOGINID waitUntilDone:YES];
//
//
#try {
//NSLog(#"before loginddd %#",LOGINID);
if(COMPANYID != 0){
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:USERNAME forKey:#"UserName"];
[prefs setObject:#"Pass" forKey:#"Pass"];
// This is suggested to synch prefs, but is not needed
[prefs synchronize];
NSLog(#"here is the login identiy%#",LOGINID);
MangoContactSelection *SenderInfoViews = [[MangoContactSelection alloc] init];
[self.navigationController pushViewController:SenderInfoViews animated:NO];
}
else{
dispatch_async(dispatch_get_main_queue(), ^ {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"bad NAME"
message:#"GOO"
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
// [self.view setNeedsDisplay];
[self.view reloadInputViews];
MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
[self.navigationController pushViewController:SenderInfoViews animated:NO];
[activityIndicator stopAnimating];
});
}
}
#catch (NSException * e) {
NSLog(#"Exception: %#", e);
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Login Failed"
message:#"Bad"
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
//[activityIndicator stopAnimating];
}
// if the data is nil do this
}else{
dispatch_async(dispatch_get_main_queue(), ^ {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"No Internet!"
message:#"Please Check your internet Connection"
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[self.view setNeedsDisplay];
MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
[self.navigationController pushViewController:SenderInfoViews animated:NO];
});
}
dispatch_async(dispatch_get_main_queue(), ^ {
//UIImage *image = [UIImage imageWithData:imageData];
//[table reloadData];
//[actIndicator stopAnimating];
[self.view reloadInputViews];
[activityIndicator stopAnimating];
// sender because that's the element that called us by clicking refresh
});
});
}else{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"No Internet!"
message:#"Please Check your internet Connection"
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[self.view setNeedsDisplay];
MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
[self.navigationController pushViewController:SenderInfoViews animated:NO];
}
}
[self.view reloadInputViews];
}//login
-(void)gobacktoContactCreate{
MangoContactSelection *gobackhome = [[MangoContactSelection alloc]init];
[self.navigationController pushViewController:gobackhome animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
//self.view setBackgroundColor:([UIColor blackColor]);
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *userName = [prefs stringForKey:#"UserName"];
//NSString *pass = [prefs stringForKey:#"Pass"];
//navigation bar
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
[self.navigationController setNavigationBarHidden: NO animated:NO];
self.navigationItem.hidesBackButton = YES;
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:#selector(gobacktoContactCreate)];
self.navigationItem.title=#"Login";
//User name text field................
usernameTF = [[UITextField alloc] initWithFrame:CGRectMake(10, 25, 300, 40)];
usernameTF.borderStyle = UITextBorderStyleRoundedRect;
usernameTF.font = [UIFont systemFontOfSize:15];
usernameTF.placeholder = #"Username";
usernameTF.text = userName;
usernameTF.autocorrectionType = UITextAutocorrectionTypeNo;
usernameTF.keyboardType = UIKeyboardTypeDefault;
usernameTF.returnKeyType = UIReturnKeyNext;
usernameTF.clearButtonMode = UITextFieldViewModeWhileEditing;
usernameTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
//User name text field................
passwordTF = [[UITextField alloc] initWithFrame:CGRectMake(10, 75, 300, 40)];
passwordTF.borderStyle = UITextBorderStyleRoundedRect;
passwordTF.font = [UIFont systemFontOfSize:15];
passwordTF.placeholder = #"Password";
passwordTF.autocorrectionType = UITextAutocorrectionTypeNo;
passwordTF.keyboardType = UIKeyboardTypeDefault;
passwordTF.returnKeyType = UIReturnKeyDone;
passwordTF.clearButtonMode = UITextFieldViewModeWhileEditing;
passwordTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
passwordTF.secureTextEntry = YES;
//create the clickable labels
//register link
registerLabel = [[UILabel alloc]initWithFrame:CGRectMake(150,170, 150, 20)];
registerLabel.text = #"Request an account";
registerLabel.font = [UIFont systemFontOfSize:12];
registerLabel.userInteractionEnabled = YES;
registerLabel.textColor = [UIColor blueColor];
UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(requestRegistration:)];
[registerLabel addGestureRecognizer:gr];
gr.numberOfTapsRequired = 1;
gr.cancelsTouchesInView = NO;
//create the label for
registerText = [[UILabel alloc]initWithFrame:CGRectMake(60,170, 90, 20)];
registerText.text = #"New to *******?";
registerText.font = [UIFont systemFontOfSize:12];
// //forgot password link
// forgotPassword = [[UILabel alloc]initWithFrame:CGRectMake(210,190, 150, 20)];
// forgotPassword.font = [UIFont systemFontOfSize:12];
// forgotPassword.textColor = [UIColor blueColor];
// forgotPassword.text = #"Forgot Password?";
// forgotPassword.userInteractionEnabled = YES;
// UITapGestureRecognizer *tapRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(requestForgottenPassword:)];
// [registerLabel addGestureRecognizer:tapRec];
// tapRec.numberOfTapsRequired = 1;
// tapRec.cancelsTouchesInView = NO;
[self.view addSubview:passwordTF];
[self.view addSubview:usernameTF];
[self.view addSubview:registerLabel];
[self.view addSubview:registerText];
// [self.view addSubview:forgotPassword];
[self addMyButton];
usernameTF.delegate = self;
passwordTF.delegate = self;
}
-(void)requestRegistration:(UITapGestureRecognizer *)gr{
//for registration
NSLog(#"request registration link clicked");
}
-(void)requestNewPassword:(UITapGestureRecognizer *)tapRec{
//for registration
NSLog(#"request password link clicked");
}
//Grabs the Json from the servlet and then parses it for the username and password.
- (void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
//NSLog(#"here is the login info from json: %#", json);
// NSString *FALSELOGIN;
COMPANYID = [json valueForKey:#"companyid"];
NSLog(#"COMPANY ID: %#", COMPANYID);
// LOGINID = [json valueForKey:#"login"];
// NSLog(#"LOGIN ID: %#", LOGINID);
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
if((textField = usernameTF)){
USERNAME = [textField.text copy];
//NSLog(#"here is the string for username;%#", USERNAME);
}
if((textField = passwordTF)){
PASSWORD = [textField.text copy];
//NSLog(#"here is the password guy %#",PASSWORD);
}
return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == usernameTF) {
[passwordTF becomeFirstResponder];
}
else{
[passwordTF resignFirstResponder];
}
return YES;
}
//- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
// [passwordTF resignFirstResponder];
//
//}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
You have added Tableview inside view of UIViewController. right?
In which view you have added UITextview.? View of UIViewController ??
You can add UITextView in UIView and by applying animation just change frame of UITextView.
Ex.
// Take View UP....
[UIView animationWithDuration:secs delay:0.0 option:option animation:^{
CGRect frame = textview.frame;
frame.origin.y = 10; // Change Y position of frame.
textview.frame = frame;
}
completion:nil];
// Take View down
[UIView animationWithDuration:secs delay:0.0 option:option animation:^{
CGRect frame = textview.frame;
frame.origin.y = 100; // Change Y position of frame.
textview.frame = frame;
}
completion:nil];
No need to take UIScrollView.
Dhaval, I beleive your solution would work, but I ended up finding exactly what i was looking for here:
http://www.youtube.com/watch?feature=player_detailpage&v=qSvDWnasJ9I
Thanks.
Hi I m creating a project where multiple Images Loading from Server With some like Count and Comment Count and a Button to like the image. I m showing the individual Images With using a Slider Controller like PageControl.
this is My code for Showing the View
-(UIView*)reloadView:(DPSliderView *)sliderView viewAtIndex:(NSUInteger)idx
{
_loading_view.hidden=TRUE;
if (idx < [photos count]) {
NSDictionary *item = [photos objectAtIndex:idx];
PhotoView *v = [[PhotoView alloc] init];
v.photoIndex = idx;
v.imageView.imageURL = [DPAPI urlForPhoto:item[#"photo_220x220"]];
NSString *placename1 = [item valueForKeyPath:#"spotting.item.name"];
NSString *firstCapChar1 = [[placename1 substringToIndex:1] capitalizedString];
NSString *cappedString1 = [placename1 stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:firstCapChar1];
v.spotNameLabel.text = cappedString1;
NSString *placename = [item valueForKeyPath:#"spotting.place.name"];
NSString *firstCapChar = [[placename substringToIndex:1] capitalizedString];
NSString *cappedString = [placename stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:firstCapChar];
NSString *place1=[NSString stringWithFormat:#"%#",cappedString];
NSString *address=[NSString stringWithFormat:#"%#",[item valueForKeyPath:#"spotting.place.address"]];
NSString *location_str3 = [NSString stringWithFormat:#"# %#, %#",place1,address];
int cap_len=[place1 length];
int address_lenth=[address length];
ZMutableAttributedString *str = [[ZMutableAttributedString alloc] initWithString:location_str3
attributes:[NSDictionary dictionaryWithObjectsAndKeys:
[[FontManager sharedManager] zFontWithName:#"Lucida Grande" pointSize:12],
ZFontAttributeName,
nil]];
[str addAttribute:ZFontAttributeName value:[[FontManager sharedManager] zFontWithName:#"Lucida Grande" pointSize:12] range:NSMakeRange(0, cap_len+3)];
[str addAttribute:ZForegroundColorAttributeName value:[UIColor colorWithRed:241/255.0f green:73.0/255.0f blue:2.0/255.0f alpha:1.0]range:NSMakeRange(0, cap_len+3)];
[str addAttribute:ZForegroundColorAttributeName value:[UIColor colorWithRed:128.0/255.0f green:121.0/255.0f blue:98.0/255.0f alpha:1.0]range:NSMakeRange(cap_len+4, address_lenth)];
v.placefontlabel.zAttributedText=str;
v.likesCountLabel.text = [NSString stringWithFormat:#"%i", [item[#"likes_count"] intValue]];
if ([_device_lang_str isEqualToString:#"es"])
{
v.shightingsLabel.text = [NSString stringWithFormat:NSLocalizedString(#"%i Vistas", nil), [item[#"sightings_count"] intValue]];
}
else
{
v.shightingsLabel.text = [NSString stringWithFormat:NSLocalizedString(#"%i Sightings", nil), [item[#"sightings_count"] intValue]];
}
if ([nolocationstr isEqualToString:#"YES"])
{
v.distanceLabel.text =[NSString stringWithFormat:#"%.2f km", [item[#"distance"] floatValue]];
}
else
{
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:[[item valueForKeyPath:#"spotting.place.lat"]floatValue] longitude:[[item valueForKeyPath:#"spotting.place.lng"] floatValue]];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:[_explore_lat_str floatValue] longitude:[_explore_lng_str floatValue]];
NSString *lat_laong=[NSString stringWithFormat:#"%f",[location1 distanceFromLocation:location2]];
int km=[lat_laong floatValue]*0.001;
NSString *distancestr=[NSString stringWithFormat:#"%d km",km];
float dist=[distancestr floatValue];
v.distanceLabel.text = [NSString stringWithFormat:#"%.2f km", dist];
}
if (![item[#"likes"] boolValue]) {
v.likeButton.enabled = YES;
v.likeButton.tag = idx;
[v.likeButton setImage:[UIImage imageNamed:#"like_new.png"] forState:UIControlStateNormal];
[v.likeButton addTarget:self action:#selector(likeAction:) forControlEvents:UIControlEventTouchUpInside];
}
else
{
v.likeButton.tag = idx;
[v.likeButton setImage:[UIImage imageNamed:#"like_new1.png"] forState:UIControlStateNormal];
}
NSArray *guides = item[#"guides"];
if ([guides count] > 0) {
NSString *guideType = [[guides objectAtIndex:0] valueForKey:#"type"];
UIImage *guidesIcon = [UIImage imageNamed:[NSString stringWithFormat:#"%#.png", guideType]];
v.guideButton.hidden = NO;
v.guideButton.tag = idx;
[v.guideButton setImage:guidesIcon forState:UIControlStateNormal];
[v.guideButton addTarget:self action:#selector(guideAction:) forControlEvents:UIControlEventTouchUpInside];
}
v.shareButton.tag = idx;
[v.shareButton addTarget:self action:#selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(photoTapGesture:)];
[v addGestureRecognizer:tapGesture];
[tapGesture release];
return [v autorelease];
} else {
UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"sc_img.png"]];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.center = CGPointMake(CGRectGetMidX(iv.bounds), 110);
[indicator startAnimating];
[iv addSubview:indicator];
[indicator release];
return [iv autorelease];
}
}
Now My question is :
If i will Click on Like Button , Then i have to change the button image as well as like count. I can able to Change the Button Image By This Method
[sender setImage:[UIImage ImageNamed:#"image.png"]];
But How can I change the Like count of the Label ? How can i access the Particular label of the View ? I have assigned the tag But , I dont know how to assign it.I dont want to Reload Whole Slider as the Photo are loading from Network (Remote Server) . Thanks for your Time.
Just keep a reference to the label and update that.
// #interface
#property (nonatomic, strong) UILabel *myLabel;
// #implementation
_myLabel.text = #"Whatever.";
If you have multiple labels, set the tags when you create your views
newView.tag = sequenceNumber +100;
And then update
-(void)updateLabelWithTag:(NSInteger)tag {
UILabel *label = (UILabel*) [self.scrollView viewWithTag:tag];
label.text = #"Whatever.";
}
Everytime i load images in a tableview and try to scroll the table view i get a crash in my simulator but no errors are showing. Could this be that there is to much memory being used.
Below is the code for 1 out the three views:
#import "ResultViewController.h"
#import "JobAddSiteViewController.h"
#import "SpecificAddViewController.h"
#import "JobAddSiteAppDelegate.h"
#import "JSONKit.h"
#implementation ResultViewController
#synthesize listData;
#synthesize listLocation;
#synthesize listPostDate;
#synthesize listLogo;
#synthesize listDescription;
#synthesize uiTableView;
#synthesize buttonPrev;
#synthesize buttonNext;
NSInteger *countPage = 1;
NSMutableArray *tempArray;
NSMutableArray *tempArray2;
NSMutableArray *tempArray3;
NSMutableArray *tempArray4;
NSMutableArray *tempArray5;
-(IBAction)done{
JobAddSiteViewController *second = [[JobAddSiteViewController alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
[second release];
}
-(void)loadData{
NSString *strURL2 = [NSString stringWithFormat:#"http://www.bestitjobs.co.uk/totaljobs.php", ""];
NSData *nsData2 = [NSData dataWithContentsOfURL:[NSURL URLWithString: strURL2]];
NSString *dataResult = [[NSString alloc] initWithData:nsData2 encoding:NSUTF8StringEncoding];
tempArray = [[NSMutableArray alloc] init];
tempArray2 = [[NSMutableArray alloc] init];
tempArray3 = [[NSMutableArray alloc] init];
tempArray4 = [[NSMutableArray alloc] init];
tempArray5 = [[NSMutableArray alloc] init];
NSString *strURL = [NSString stringWithFormat:#"http://www.bestitjobs.co.uk/appresults3.php?pg=%d", countPage];
NSData *nsData = [NSData dataWithContentsOfURL:[NSURL URLWithString: strURL]];
NSDictionary *listDictionary = [nsData objectFromJSONData];
NSArray* people =[listDictionary objectForKey:#"jobs"];
for (NSDictionary *person in people) {
NSString *str = [NSString stringWithFormat:#"%#", [person valueForKey:#"position"]];
NSString *str2 = [NSString stringWithFormat:#"%#", [person valueForKey:#"subcounty"]];
NSString *str3 = [NSString stringWithFormat:#"%#", [person valueForKey:#"postdate"]];
NSString *str4 = [NSString stringWithFormat:#"%#", [person valueForKey:#"logo"]];
NSString *str5 = [NSString stringWithFormat:#"%#", [person valueForKey:#"description"]];
if(![str isEqualToString:#"<null>"])
{
NSString *position = [person objectForKey:#"position"];
[tempArray addObject: position];
if(![str2 isEqualToString:#"<null>"])
{
NSString *subcounty = [person objectForKey:#"subcounty"];
[tempArray2 addObject: subcounty];
}
else{
[tempArray2 addObject: #"-"];
}
if(![str3 isEqualToString:#"<null>"])
{
NSString *postDate = [person objectForKey:#"postdate"];
[tempArray3 addObject: postDate];
}
else{
[tempArray3 addObject: #"-"];
}
if(![str4 isEqualToString:#"<null>"])
{
NSString *logo = [person objectForKey:#"logo"];
[tempArray4 addObject: [NSString stringWithFormat:#"http://www.bestitjobs.co.uk/employers/logo/Files/%#", logo]];
}
else{
[tempArray4 addObject: [NSString stringWithFormat:#"http://www.bestitjobs.co.uk/employers/logo/Files/%#", "noimage.gif"]];
}
if(![str5 isEqualToString:#"<null>"])
{
NSString *description = [person objectForKey:#"description"];
[tempArray5 addObject: description];
}
else{
[tempArray5 addObject: #"-"];
}
}
}
if (countPage == 1) {
[self.buttonPrev setEnabled:FALSE];
}
else {
[self.buttonPrev setEnabled:TRUE];
}
NSInteger val = [dataResult intValue];
NSInteger pageEnd = val/10;
if (countPage < pageEnd) {
[self.buttonNext setEnabled:TRUE];
}
else {
[self.buttonNext setEnabled:FALSE];
}
//NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:#"iPhone", #"iPod",#"iPad",nil];
self.listData = tempArray;
self.listLocation = tempArray2;
self.listPostDate = tempArray3;
self.listLogo = tempArray4;
self.listDescription = tempArray5;
[self.listData release];
[self.listLocation release];
[self.listPostDate release];
[self.listLogo release];
[self.listDescription release];
tempArray = nil;
tempArray2 = nil;
tempArray3 = nil;
tempArray4 = nil;
tempArray5 = nil;
}
- (void)viewDidLoad {
[self loadData];
[super viewDidLoad];
}
- (void)dealloc {
[tempArray dealloc];
[tempArray2 dealloc];
[tempArray3 dealloc];
[tempArray4 dealloc];
[tempArray5 dealloc];
[self.listData dealloc];
[self.listLocation dealloc];
[self.listPostDate dealloc];
[self.listLogo dealloc];
[self.listDescription dealloc];
[super dealloc];
}
#pragma mark -
#pragma mark Table View Data Source Methods
- (IBAction)prev{
countPage = countPage - 1;
[self.listData removeAllObjects];
[self.listLocation removeAllObjects];
[self.listPostDate removeAllObjects];
[self.listLogo removeAllObjects];
//NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:#"1", #"2",#"3",nil];
//self.listData = array;
[self loadData];
[self.uiTableView reloadData];
}
- (IBAction)next{
countPage = countPage + 1;
[self.listData removeAllObjects];
[self.listLocation removeAllObjects];
[self.listPostDate removeAllObjects];
[self.listLogo removeAllObjects];
//NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:#"1", #"2",#"3",nil];
//self.listData = array;
[self loadData];
[self.uiTableView reloadData];
}
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
JobAddSiteAppDelegate *ja = (JobAddSiteAppDelegate *)[[UIApplication sharedApplication] delegate];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
for (UIView *view in cell.contentView.subviews){
if ([view isKindOfClass:[UILabel class]]){
UILabel *label = (UILabel *)view;
if (label.tag == 1) {
ja.jobText = label.text;
}
if (label.tag == 2) {
ja.locationText = label.text;
}
if (label.tag == 3) {
ja.dateText = label.text;
}
if (label.tag == 4) {
}
if (label.tag == 5) {
ja.specificText = label.text;
}
}
if ([view isKindOfClass:[UIImageView class]]){
UIImageView *image = (UIImageView *)view;
if (image.tag = 4){
ja.logoText = image.image;
}
}
}
SpecificAddViewController *second = [[SpecificAddViewController alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
[second release];
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [self.listData count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath
*)indexPath
{
if (indexPath.section == 1 && indexPath.row == 1) {
return 65;
}
return 65;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = #"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
UILabel *labelMain;
UILabel *labelLocation;
UILabel *labelDate;
UIImageView *image;
UILabel *ref;
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
image = [[[UIImageView alloc] initWithFrame:CGRectMake(0,3,80,62)] autorelease];
image.tag = 4;
[cell.contentView addSubview:image];
labelMain = [[[UILabel alloc] initWithFrame:CGRectMake(90,3,200,20)] autorelease];
labelMain.tag = 1;
labelMain.font = [UIFont systemFontOfSize:14.0];
[cell.contentView addSubview:labelMain];
labelLocation = [[[UILabel alloc] initWithFrame:CGRectMake(90,20,200,20)] autorelease];
labelLocation.tag = 2;
labelLocation.font = [UIFont systemFontOfSize:12.0];
labelLocation.textColor = [UIColor darkGrayColor];
[cell.contentView addSubview:labelLocation];
labelDate = [[[UILabel alloc] initWithFrame:CGRectMake(90,40,200,20)] autorelease];
labelDate.tag = 3;
labelDate.font = [UIFont systemFontOfSize:12.0];
labelDate.textColor = [UIColor darkGrayColor];
[cell.contentView addSubview:labelDate];
ref = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)] autorelease];
ref.tag = 5;
[cell.contentView addSubview:ref];
}
[(UILabel *)[cell.contentView viewWithTag:1] setText:[self.listData objectAtIndex:indexPath.row]];
[(UILabel *)[cell.contentView viewWithTag:2] setText:[self.listLocation objectAtIndex:indexPath.row]];
[(UILabel *)[cell.contentView viewWithTag:3] setText:[self.listPostDate objectAtIndex:indexPath.row]];
[(UILabel *)[cell.contentView viewWithTag:5] setText:[self.listDescription objectAtIndex:indexPath.row]];
NSString *imagePath = [self.listLogo objectAtIndex:indexPath.row];
image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imagePath]]];
return cell;
}
#end
The call
image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imagePath]]];
will block the execution thread and being indeterminately long in terms of network use this is a bad thing. Each of your cells needs to wait to the image to load.
Check out "lazy loading of tableView cells" as a research topic.
Instead you should give the URL to the cell and tell it to load the image off the main thread.
as in
[cell loadImageAtURL:someURL];
and within a UITableViewCell subclass implementation
-(void)loadImageAtURL:(NSURL *)aurl
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSData *data = [NSData dataWithContentsOfURL:aurl];
if (data) {
UIImage *image = [UIImage imageWithData:data];
//must update UI on main queue
dispatch_async(dispatch_get_main_queue() ,^{
self.cellImageView = image;
}
}
});
}
Theres also a ton of Obj-C image loaders . EGOCache is my go to library but have a look round.
In summary the cell needs to own the image load process not the tableview because theres no guarantee that the cell will not be reused before the image loads and displays.
NSInteger is a primitive type, which means it can be stored locally on the stack. You don't need to use a pointer to access it. The way you are using it i think is a problem, getting the pointer value instead of the actual value of the primitive type.
I think this is what you want for the declaration/initialization of countPage:
NSInteger countPage = 1;
I am loading a mapview with annotation. I have written the code as shown below. As I am new to OOPS I know that I may have committed a lot of mistakes. It would be really helpful, if someone would review my code and give some suggestions.
- (void)viewDidLoad
{
[super viewDidLoad];
if(groupOrContactSelected){
UIBarButtonItem *infoButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.infoButton];
UIBarButtonItem *segmentedButton = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSArray *toolbarItems = [NSArray arrayWithObjects: infoButtonItem, flexibleSpace, segmentedButton, nil];
[self setToolbarItems:toolbarItems];
self.navigationController.toolbar.translucent = true;
self.navigationController.toolbarHidden = NO;
[infoButtonItem release];
[segmentedButton release];
[flexibleSpace release];
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
mapView.delegate=self;
[self.view addSubview:mapView];
addressbook = ABAddressBookCreate();
for (i = 0; i<[groupContentArray count]; i++) {
person = ABAddressBookGetPersonWithRecordID(addressbook,[[groupContentArray objectAtIndex:i] intValue]);
ABMultiValueRef addressProperty = ABRecordCopyValue(person, kABPersonAddressProperty);
NSArray *address = (NSArray *)ABMultiValueCopyArrayOfAllValues(addressProperty);
for (NSDictionary *addressDict in address)
{
addAnnotation = nil;
firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
NSString *country = [addressDict objectForKey:#"Country"];
NSString *streetName = [addressDict objectForKey:#"Street"];
NSString *cityName = [addressDict objectForKey:#"City"];
NSString *stateName = [addressDict objectForKey:#"State"];
NSString *fullAddress = [streetName stringByAppendingFormat:#"%#/%#/%#", cityName, stateName, country];
mapCenter = [self getLocationFromAddressString:fullAddress];
if(stateName != NULL || country != NULL || streetName != NULL || cityName != NULL){
addAnnotation = (SJAddressAnnotation *)[mapView dequeueReusableAnnotationViewWithIdentifier:[groupContentArray objectAtIndex:i]];
if(addAnnotation == nil){
addAnnotation = [[[SJAddressAnnotation alloc] initWithCoordinate:mapCenter title:firstName SubTitle:lastName Recordid:[groupContentArray objectAtIndex:i] ] autorelease];
[mapView addAnnotation:addAnnotation];}
}
}
CFRelease(addressProperty);
}
[self zoomToFitMapAnnotations:mapView];
[self.navigationItem setHidesBackButton:YES animated:YES];
NSString *mapTitle = localizedString(#"MAP_TITLE");
[self setTitle:mapTitle];
[segmentedControl addTarget:self action:#selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
NSString *close = localizedString(#"CLOSE");
UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:close style:UIBarButtonItemStylePlain target:self action:#selector(onClose:)];
self.navigationItem.rightBarButtonItem = closeButton;
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[closeButton release];
}
[searchDirectionSegmentedControl release];
[mapView release];
}
I may have committed a lot of mistakes. All suggestions will be appreciated. Thanks
Here is link which you can prefer and know how to structure the code properly http://www.highoncoding.com/Articles/804_Introduction_to_MapKit_Framework_for_iPhone_Development.aspx
Hope this help you.