Arranging the values in ascending order in tableViewCell - iphone

In my application am using scrollView with 4 Buttons.
When we click on any one of the buttons a table will be displayed with data row by row dynamically.
Now my problem is to arrange them into ascending order.
Sample code is
this is for adding buttons to scrollview this is in one class
browseScrollView.hidden = NO;
browseScrollView.frame = CGRectMake(15, 57, 480, 44);
[browseScrollView setContentSize:CGSizeMake(600, 40)];
firstButton = [UIButton buttonWithType:UIButtonTypeCustom];
[firstButton setFrame:CGRectMake(5,3,91,37)];
[firstButton setImage:[UIImage imageNamed:#"genres.png"] forState:UIControlStateNormal];
firstButton.tag = 1;
[firstButton addTarget:self action:#selector(fourthPageSongSelction:) forControlEvents:UIControlEventTouchDown];
[browseScrollView addSubview:firstButton];
secondButton = [UIButton buttonWithType:UIButtonTypeCustom];
[secondButton setFrame:CGRectMake(110,3,91,37)];
[secondButton setImage:[UIImage imageNamed:#"artists.png"] forState:UIControlStateNormal];
secondButton.tag = 2;
[secondButton addTarget:self action:#selector(fourthPageSongSelction:) forControlEvents:UIControlEventTouchDown];
[browseScrollView addSubview:secondButton];
thirdButton = [UIButton buttonWithType:UIButtonTypeCustom];
[thirdButton setFrame:CGRectMake(209,3,91,37)];
thirdButton.tag = 3;
[thirdButton setImage:[UIImage imageNamed:#"albums.png"] forState:UIControlStateNormal];
[thirdButton addTarget:self action:#selector(fourthPageSongSelction:) forControlEvents:UIControlEventTouchDown];
[browseScrollView addSubview:thirdButton];
fourthButton = [UIButton buttonWithType:UIButtonTypeCustom];
[fourthButton setFrame:CGRectMake(317,3,91,37)];
fourthButton.tag = 4;
[fourthButton setImage:[UIImage imageNamed:#"songs.png"] forState:UIControlStateNormal];
[fourthButton addTarget:self action:#selector(fourthPageSongSelction:) forControlEvents:UIControlEventTouchDown];
[browseScrollView addSubview:fourthButton];
tableView.hidden = NO;
tableView.frame = CGRectMake(5, 100, 235, 200);
tableView.showsVerticalScrollIndicator = NO;
This is the method i used to add values to table row this in another class which is subclass of TableViewCell
-(void) showFourthPageControlValues :(int) currRow :(int)val
{
int value = val;
TonifyAppDelegate *appDelegate = (TonifyAppDelegate *)[UIApplication sharedApplication].delegate;
if (value == 1)
{
genresLabel1.hidden = NO;
genresLabel2.hidden = NO;
genresButton.hidden = NO;
artistLabel1.hidden = YES;
artistLabel2.hidden = YES;
artistButton.hidden = YES;
albumLabel1.hidden = YES;
albumLabel2.hidden = YES;
albumButton.hidden = YES;
songsLabel1.hidden = YES;
songsLabel2.hidden = YES;
songsButton.hidden = YES;
[genresLabel1 setText:[[appDelegate.songsList objectAtIndex:currRow] valueForKey:#"Genre"]];
[genresLabel2 setText:[[appDelegate.songsList objectAtIndex:currRow] valueForKey:#"SongName"]];
[genresButton addTarget:self.delegateController action:#selector(songTypeSelAction:) forControlEvents:UIControlEventTouchUpInside];
genresButton.tag = currRow;
}
if (value == 2)
{
genresLabel1.hidden = YES;
genresLabel2.hidden = YES;
genresButton.hidden = YES;
artistLabel1.hidden = NO;
artistLabel2.hidden = NO;
artistButton.hidden = NO;
albumLabel1.hidden = YES;
albumLabel2.hidden = YES;
albumButton.hidden = YES;
songsLabel1.hidden = YES;
songsLabel2.hidden = YES;
songsButton.hidden = YES;
[artistLabel1 setText:[[appDelegate.songsList objectAtIndex:currRow] valueForKey:#"ArtistName"]];
[artistLabel2 setText:[[appDelegate.songsList objectAtIndex:currRow] valueForKey:#"SongName"]];
[artistButton addTarget:self.delegateController action:#selector(songTypeSelAction:) forControlEvents:UIControlEventTouchUpInside];
artistButton.tag = currRow;
}
if (value == 3)
{
genresLabel1.hidden = YES;
genresLabel2.hidden = YES;
genresButton.hidden = YES;
artistLabel1.hidden = YES;
artistLabel2.hidden = YES;
artistButton.hidden = YES;
albumLabel1.hidden = NO;
albumLabel2.hidden = NO;
albumButton.hidden = NO;
songsLabel1.hidden = YES;
songsLabel2.hidden = YES;
songsButton.hidden = YES;
[albumLabel1 setText:[[appDelegate.songsList objectAtIndex:currRow] valueForKey:#"AlbumName"]];
[albumLabel2 setText:[[appDelegate.songsList objectAtIndex:currRow] valueForKey:#"SongName"]];
[albumButton addTarget:self.delegateController action:#selector(songTypeSelAction:) forControlEvents:UIControlEventTouchUpInside];
albumButton.tag = currRow;
}
if (value == 4)
{
genresLabel1.hidden = YES;
genresLabel2.hidden = YES;
genresButton.hidden = YES;
artistLabel1.hidden = YES;
artistLabel2.hidden = YES;
artistButton.hidden = YES;
albumLabel1.hidden = NO;
albumLabel2.hidden = NO;
albumButton.hidden = NO;
songsLabel1.hidden = NO;
songsLabel2.hidden = NO;
songsButton.hidden = NO;
[songsLabel1 setText:[[appDelegate.songsList objectAtIndex:currRow] valueForKey:#"SongName"]];
[songsLabel2 setText:[[appDelegate.songsList objectAtIndex:currRow] valueForKey:#"AlbumName"]];
[songsButton addTarget:self.delegateController action:#selector(songTypeSelAction:) forControlEvents:UIControlEventTouchUpInside];
songsButton.tag = currRow;
}
}
This is the method i am using for selection or row
-(void) songTypeSelAction :(id) sender
{
NSLog(#"songTypeSelAction");
UIButton *btn = (UIButton *) sender;
NSLog(#"songTypeSelAction bttn.tag: %d", btn.tag);
if ([self.delegateController respondsToSelector:#selector(songImageSelAction:)])
{
}
}

NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:#"SongName" ascending:TRUE];
NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:#"AlbumName" ascending:TRUE];
[appDelegate.songsList sortUsingDescriptors:[NSArray arrayWithObjects:sortDescriptor1,sortDescriptor2, nil]];

If you want ti preferable..Than you can do this..First take new view....Add four buttons and tableView.
Than follow this: Editor -> Embed In -> ScrollView
Than on button's click event show the table and Don't forget to reload tableview data at show time.
If having any query ask me.

Related

How to keep selection on radio buttons after clicking previous button

For my Quiz app, i am creating 4 custom radio buttons for 4 answers by setting active and inactive images . When i select the button the state changing to active but when i press previous button the state going to inactive .
Code for creating Custom buttons
//answer 1
targetLabel = [[UILabel alloc] init];
CGSize labelSize = CGSizeMake(240, 9999);
CGSize theStringSize = [ans1 sizeWithFont:targetLabel.font constrainedToSize:labelSize lineBreakMode:targetLabel.lineBreakMode];
targetLabel.frame = CGRectMake(targetLabel0.frame.origin.x+40, targetLabel0.frame.size.height+40, theStringSize.width, theStringSize.height);
targetLabel.text = ans1;
[targetLabel setNumberOfLines:0];
targetLabel.backgroundColor=[UIColor clearColor];
[targetLabel sizeToFit];
[scroll addSubview:targetLabel];
// button 1
ans1btn = [[UIButton alloc] initWithFrame:CGRectMake(15,targetLabel.frame.origin.y-5,30,30)];
ans1btn.backgroundColor=[UIColor redColor];
[ans1btn setSelected:NO];
[ans1btn setBackgroundImage:[UIImage imageNamed:#"gray.png"]
forState:UIControlStateNormal];
[ans1btn setBackgroundImage:[UIImage imageNamed:#"green.png"]
forState:UIControlStateSelected];
ans1btn.adjustsImageWhenHighlighted=YES;
[ans1btn addTarget:self
action:#selector(checkboxSelected:)
forControlEvents:UIControlEventTouchUpInside];
ans1btn.tag=1;
[scroll addSubview:ans1btn];
Calling method
-(void)checkboxSelected:(id)sender
{
checkBoxSelected = TRUE;
[ans1btn setSelected:checkBoxSelected];
if(checkBoxSelected==TRUE)
{
checkBoxSelected1=FALSE;
[ans1btn1 setSelected:checkBoxSelected1];
[ans1btn2 setSelected:checkBoxSelected1];
[ans1btn3 setSelected:checkBoxSelected1];
checkBoxSelected=TRUE;
targetLabel.textColor=[UIColor blackColor];
targetLabel1.textColor=[UIColor grayColor];
targetLabel2.textColor=[UIColor grayColor];
targetLabel3.textColor=[UIColor grayColor];
}
else
{
NSLog(#"the button is not selected");
}
}
Like that i am calling other button actions also
Can anyone please help me.
Thanks in advance.
There is no actual radio button in iOS but you can use the following code to do what you want,
First, second, third and fourthButtonTags are values those already have been set in .xib or .m file. Specific numbers are also can be used.
In your .h file;
#property (strong, nonatomic) UIButton *firstButton, *secondButton, *thirdButton, *fourthButton;
In your .m file;
- (IBAction)buttonSelection:(id)sender {
UIButton *senderButton = (UIButton *) sender;
if (senderButton.tag == firstButtonTag) {
if (_firstButton.selected) {
_firstButton.selected = NO;
}
else {
_firstButton.selected = YES;
_secondButton.selected = NO;
_thirdButton.selected = NO;
_fourthButton.selected = NO;
}
}
else if (senderButton.tag == secondButtonTag) {
if (_secondButton.selected) {
_secondButton.selected = NO;
}
else {
_secondButton.selected = YES;
_firstButton.selected = NO;
_thirdButton.selected = NO;
_fourthButton.selected = NO;
}
}
else if (senderButton.tag == thirdButtonTag) {
if (_thirdButton.selected) {
_thirdButton.selected = NO;
}
else {
_thirdButton.selected = YES;
_firstButton.selected = NO;
_secondButton.selected = NO;
_fourthButton.selected = NO;
}
}
else if (senderButton.tag == fourthButtonTag) {
if (_fourthButton.selected) {
_fourthButton.selected = NO;
}
else {
_fourthButton.selected = YES;
_firstButton.selected = NO;
_secondButton.selected = NO;
_thirdButton.selected = NO;
}
}
}
try like this ,here define one button globally and play with that button,no need to take tag and all other stuff
#property(nonatomic,retain)UIButton *previousSelectedBtn;
- (IBAction)radioButtonSelection:(UIButton *)sender {
sender.selected=YES;
if(_previousSelectedBtn)
_previousSelectedBtn.selected=NO;
_previousSelectedBtn=sender;
}

MapView annotations change their layer order when touched

Small question, i've got a few annotations on a map view. Sometimes they tend to overlap when they are very close to each other and that's ok, but when i touch them they switch their layer position. Those that were in the back are now in the front and vice versa.
So i checked my didSelectAnnotation function but there is literarily no code in that function so it couldn't be it.
I couldn't think of anything else that might cause it.
Do you know how to fix it so it won't change layer position??
This is my viewForAnnotation code:
annImg = [[szAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"current"];
szPointAnnotation *pointAnnotation = annotation;
if (appDelegate.homePage || ([pointAnnotation.tag intValue] >= 10000))
{
annImg.canShowCallout = NO;
annImg.backgroundColor = [UIColor clearColor];
annImg.frame = CGRectMake(0, /*0*/-78, 70, /*78*/156);
UIImageView *currentUserPictureView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 60, 60)];
int newTag = [pointAnnotation.tag intValue]-10000;
UIImage *currentUserPicture;
if ([pointAnnotation.tag intValue] >= 10000) {
currentUserPicture = [UIImage imageWithData:[usersData getKeyForIndexWithKey:#"UserImageData" forIndex:newTag]];
}else{
currentUserPicture = [UIImage imageWithData:[usersData getKeyForIndexWithKey:#"UserImageData" forIndex:[pointAnnotation.tag intValue]]];
}
currentUserPictureView.image = currentUserPicture;
userLocationButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 70, 78)];
[userLocationButton setBackgroundImage:[UIImage imageNamed:#"pin.png"] forState:UIControlStateNormal];
[userLocationButton addTarget:self action:#selector(centerOnUser:) forControlEvents:UIControlEventTouchUpInside];
if ([pointAnnotation.tag intValue] >= 10000) {
userLocationButton.tag = newTag;
}else{
userLocationButton.tag = [pointAnnotation.tag intValue];
}
[userLocationButton setBackgroundColor:[UIColor clearColor]];
[annImg addSubview:userLocationButton];
[userLocationButton addSubview:currentUserPictureView];
[userLocationButton release];
[currentUserPictureView release];
[currentUserPicture release];
}

How to delete label that created programmatically?

I am creating two label programmatically using this code..
-(void)addLabel:(id)sender
{
ExampleAppDataObject* theDataObject = [self theAppDataObject];
theDataObject.count = theDataObject.count+1;
NSLog(#"count is :%i",theDataObject.count);
if (theDataObject.count == 2) {
addLabel.enabled = NO;
}
if (theDataObject.count == 1) {
CGRect imageFrame = CGRectMake(10, 10, 150, 80);
labelResizableView = [[UserResizableView alloc] initWithFrame:imageFrame];
blabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 35, 100, 100)];
blabel.text = #"Write here";
//alabel.text = self.newsAsset.title;
blabel.adjustsFontSizeToFitWidth = NO;
blabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
blabel.font = [UIFont boldSystemFontOfSize:18.0];
blabel.textColor = [UIColor blueColor];
// alabel.shadowColor = [UIColor whiteColor];
// alabel.shadowOffset = CGSizeMake(0, 1);
blabel.backgroundColor = [UIColor clearColor];
blabel.lineBreakMode = UILineBreakModeWordWrap;
blabel.numberOfLines = 10;
blabel.minimumFontSize = 8.;
blabel.adjustsFontSizeToFitWidth = YES;
[blabel sizeToFit];
labelResizableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// enable touch delivery
blabel.userInteractionEnabled = YES;
//tao gasture recognizer for label
UITapGestureRecognizer *doubleTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(blabelTap:)];
doubleTap.numberOfTapsRequired = 2;
[blabel addGestureRecognizer:doubleTap];
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:#selector(longPress:)];
[longPressGesture setMinimumPressDuration:1];
[blabel addGestureRecognizer:longPressGesture];
//Calculate the expected size based on the font and linebreak mode of your label
CGSize maximumLabelSize = CGSizeMake(296,9999);
CGSize expectedLabelSize = [greetString sizeWithFont:blabel.font
constrainedToSize:maximumLabelSize
lineBreakMode:blabel.lineBreakMode];
//adjust the label the the new height.
CGRect newFrame = blabel.frame;
newFrame.size.height = expectedLabelSize.height+40;
newFrame.size.width = expectedLabelSize.width+40;
blabel.frame = newFrame;
labelResizableView.frame = newFrame;
labelResizableView.contentView = blabel;
labelResizableView.delegate = self;
labelResizableView.tag =2;
[self.view addSubview:labelResizableView];
}else if (theDataObject.count == 2) {
CGRect imageFrame = CGRectMake(10, 10, 150, 80);
labelResizableView = [[UserResizableView alloc] initWithFrame:imageFrame];
clabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 35, 100, 100)];
clabel.text = #"Write here";
//alabel.text = self.newsAsset.title;
clabel.adjustsFontSizeToFitWidth = NO;
clabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
clabel.font = [UIFont boldSystemFontOfSize:18.0];
clabel.textColor = [UIColor blueColor];
// alabel.shadowColor = [UIColor whiteColor];
// alabel.shadowOffset = CGSizeMake(0, 1);
clabel.backgroundColor = [UIColor clearColor];
clabel.lineBreakMode = UILineBreakModeWordWrap;
clabel.numberOfLines = 10;
clabel.minimumFontSize = 8.;
clabel.adjustsFontSizeToFitWidth = YES;
[clabel sizeToFit];
labelResizableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// enable touch delivery
clabel.userInteractionEnabled = YES;
//tao gasture recognizer for label
UITapGestureRecognizer *doubleTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(clabelTap:)];
doubleTap.numberOfTapsRequired = 2;
[clabel addGestureRecognizer:doubleTap];
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:#selector(longPress:)];
[longPressGesture setMinimumPressDuration:1];
[clabel addGestureRecognizer:longPressGesture];
//Calculate the expected size based on the font and linebreak mode of your label
CGSize maximumLabelSize = CGSizeMake(296,9999);
CGSize expectedLabelSize = [greetString sizeWithFont:clabel.font
constrainedToSize:maximumLabelSize
lineBreakMode:clabel.lineBreakMode];
//adjust the label the the new height.
CGRect newFrame = blabel.frame;
newFrame.size.height = expectedLabelSize.height+40;
newFrame.size.width = expectedLabelSize.width+40;
clabel.frame = newFrame;
labelResizableView.frame = newFrame;
labelResizableView.contentView = clabel;
labelResizableView.delegate = self;
labelResizableView.tag=3;
[self.view addSubview:labelResizableView];
}
}
And when user long press button than it will be deleted...
- (void)longPress:(UILongPressGestureRecognizer *)longPressGesture {
if (longPressGesture.state == UIGestureRecognizerStateEnded) {
//NSLog(#"Long press Ended");
// NSLog(#"blabel long pressed");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Delete Label" message:#"Want delete label" delegate:self cancelButtonTitle:#"No" otherButtonTitles:#"Yes",nil];
[alert show];
}
else {
//NSLog(#"Long press detected.");
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Yes"])
{
ExampleAppDataObject* theDataObject = [self theAppDataObject];
if (theDataObject.count!=0) {
theDataObject.count = theDataObject.count-1;
}
addLabel.enabled = YES;
[labelResizableView removeFromSuperview];
// NSLog(#"yes btn tapped");
}
}
but now when i longpree blabel than still clabel is deleted and it will never delete blabel.thanx in advance.
Use the Tag property to remove the labelResizableView.
-(void)addLabel:(id)sender
{
labelResizableView = [[UserResizableView alloc] initWithFrame:imageFrame];
labelResizableView.tag = 100;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Yes"])
{
ExampleAppDataObject* theDataObject = [self theAppDataObject];
if (theDataObject.count!=0) {
theDataObject.count = theDataObject.count-1;
}
addLabel.enabled = YES;
UILabel *tempLabel = (UILabel *)[self.view viewWithTag:100];
if(tempLabel)
[tempLabel removeFromSuperview];
}
}
hope this code help you :)
NSArray *subArray = [self.view subviews];
if([subArray count] != 0) {
for(int i = 0 ; i < [subArray count] ; i++) {
[[subArray objectAtIndex:i] removeFromSuperview];
}
}
To add control in your view:
[self.view addsubview:yourcontrolid];
ex:
[self.view addsubview:labelid];
To add control from your view:
[controlid removefromsuperview];
ex
[labelid removefromsuperview];
you are adding with :
[self.view addSubview:labelResizableView];
than remove it the labelResizableView, and release the clabel or blabel, whatever is in your case.
Maybe this gives an example
It is because your code
else if (theDataObject.count == 2) {
is calling and in this code you are adding
labelResizableView.contentView = clabel;
and then you are adding this to you view
[self.view addSubview:labelResizableView];
So when you are deleting labelResizableView
[labelResizableView removeFromSuperview];
So the result is you are adding labelResizableView 2 times and remove the labelResizableView which have clabel.

Thumbnail grid of images

How does one create a dynamic thumbnail grid?
How is a grid created with thumbnails of images like the photo app on iphone?
How are these spaces arranged dynamically? e.g. adding and removing thumbnails.
this is my simple grid view app
- (void)viewDidAppear:(BOOL)animated {
[[Grid_ViewAppDelegate sharedAppDelegate] hideLoadingView];
temp = temp+1;
if (temp ==1){
NSLog(#"temp:%d",temp);
int n = 20; //Numbers of array;
NSArray *t = [[NSArray alloc] initWithObjects:#"calpie.gif",#"chrysler_electric.png",#"chrysler_fiat_cap.gif",#"cleanup.gif",#"ecylindri.gif",#"elect08.png",#"globe.gif",#"heat.gif",#"insur.gif"
,#"jobs.gif",#"office.gif",#"opec1.gif",#"orng_cap.gif",#"poll.gif",#"pollen.gif",#"purbar.gif",#"robinson.gif",#"robslink_cap.gif",#"scot_cap.gif",#"shoes.gif",nil];
myScrollView.contentSize = CGSizeMake(320, 460+n*2);
myScrollView.maximumZoomScale = 4.0;
myScrollView.minimumZoomScale = 1;
myScrollView.clipsToBounds = YES;
myScrollView.delegate = self;
NSString *mxiURL = #"http://meta-x.com/biflash/images/";
int i =0,i1=0;
while(i<n){
int yy = 4 +i1*79;
for(int j=0; j<4;j++){
if (i>=n) break;
CGRect rect;
rect = CGRectMake(4+79*j, yy, 75, 75);
UIButton *button=[[UIButton alloc] initWithFrame:rect];
[button setFrame:rect];
NSString *nn = [mxiURL stringByAppendingString:[t objectAtIndex:i]];
UIImage *buttonImageNormal=[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: nn]]];
[button setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
button.tag =i;
[button addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside ];
//[self.view addSubview:button];
[myScrollView addSubview:button];
//[buttonImageNormal release];
[button release];
i++;
//
}
i1 = i1+1;
//i=i+4;
}
}
}
in AppDelegate
+ (Grid_ViewAppDelegate *)sharedAppDelegate
{
return (Grid_ViewAppDelegate *)[UIApplication sharedApplication].delegate;
}
- (void)showLoadingView
{
if (loadingView == nil)
{
loadingView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
loadingView.opaque = NO;
loadingView.backgroundColor = [UIColor grayColor];
loadingView.alpha = 0.5;
UIActivityIndicatorView *spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(142.0, 222.0, 37.0, 37.0)];
[spinningWheel startAnimating];
spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[loadingView addSubview:spinningWheel];
[spinningWheel release];
CGRect label = CGRectMake(142.0f, 255.0f, 71.0f, 20.0f);
lblLoading = [[UILabel alloc] initWithFrame:label];
lblLoading.textColor = [UIColor whiteColor];
lblLoading.font = [UIFont boldSystemFontOfSize:14];
// UILabel
lblLoading.backgroundColor =[UIColor clearColor];
[lblLoading setText:#"Loading..."];
//[lblLoading setTextAlignment:UITextAlignmentCenter];
[loadingView addSubview:lblLoading];
}
[window addSubview:loadingView];
}
- (void)hideLoadingView
{
[loadingView removeFromSuperview];
}
definitely if u apply this logic. u get succeed

problem in adding second UIbutton in cameraOverlayView

problem in adding second UIbutton in cameraOverlayView ,here i am able to add the first button but not able to add second button with following code
- (void)pickAndDecodeFromSource:(UIImagePickerControllerSourceType) sourceType {
[self reset];
// Create the Image Picker
if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {
UIImagePickerController* aPicker =
[[[UIImagePickerController alloc] init] autorelease];
aPicker.sourceType = sourceType;
aPicker.delegate = self;
self.picker = aPicker;
// [[NSUserDefaults standardUserDefaults] boolForKey:#"allowEditing"];
BOOL isCamera = (sourceType == UIImagePickerControllerSourceTypeCamera);
if ([picker respondsToSelector:#selector(setAllowsEditing:)]) {
// not in 3.0
[picker setAllowsEditing:!isCamera];
}
if (isCamera) {
if ([picker respondsToSelector:#selector(setShowsCameraControls:)]) {
[picker setShowsCameraControls:NO];
UIButton *cancelButton =
[UIButton buttonWithType:UIButtonTypeRoundedRect];
NSString *cancelString =
NSLocalizedString(#"DecoderViewController cancel button title", #"");
CGFloat height = [UIFont systemFontSize];
CGSize size =
[cancelString sizeWithFont:[UIFont systemFontOfSize:height]];
[cancelButton setTitle:cancelString forState:UIControlStateNormal];
//cancelButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"CancelButtonForButton.png"]];
//cancelButton.backgroundColor = [UIColor clearColor];
//cancelButton.backgroundColor = [UIColor greenColor];
[cancelButton setImage:[UIImage imageNamed:#"cancelForButton.png"] forState:UIControlStateNormal];
//[cancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
CGRect appFrame = [[UIScreen mainScreen] bounds];
static const int kMargin = 10;
static const int kInternalXMargin = 10;
static const int kInternalYMargin = 10;
CGRect frame = CGRectMake(kMargin,
appFrame.size.height - (height + 2*kInternalYMargin + kMargin),
2*kInternalXMargin + size.width,
height + 2*kInternalYMargin);
[cancelButton setFrame:frame];
[cancelButton addTarget:self
action:#selector(cancel:)
forControlEvents:UIControlEventTouchUpInside];
picker.cameraOverlayView = cancelButton;
// The camera takes quite a while to start up. Hence the 2 second delay.
[self performSelector:#selector(takeScreenshot)
withObject:nil
afterDelay:2.0];
//cancelButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg.png"]];
}
}
// Picker is displayed asynchronously.
[self presentModalViewController:picker animated:YES];
} else {
NSLog(#"Attempted to pick an image with illegal source type '%d'", sourceType);
}
}
The issue is that you are replacing the camera overlay with the first button - so creating the second button and using "picker.cameraOverlayView = newButton;" replaces the camera-overlay again.
The solution is to create a parent UIView, add both buttons to it, and then set the camera overlay to be the parent UIView.