Custom buttons on UIPickerView are in disable state - ios6

i have added custom "Done" and "Cancel" button on PickerView like:
- (void)customBtnsToPickerView
{
UIToolbar *toolBar= [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[toolBar setBarStyle:UIBarStyleBlackOpaque];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:#"Cancel" style:UIBarButtonItemStyleDone target:self action:#selector(cancelActionOfPickerView:)];
[barItems addObject:cancelBtn];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleDone target:self action:#selector(doneActionOfPickerView:)];
[barItems addObject:doneBtn];
[toolBar setItems:[NSArray arrayWithArray:barItems]];
[self.pickerView addSubview:toolBar];
}
But they are always in disable state. i don't know what's issue inside.
i am using iphone 5 with IOS 6.1...

Related

Tool bar in IOS 6 not working properly

i am adding Tool bar to a UIView like :
UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(0, 0, 300, 44);
UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithTitle:#"Send" style:UIBarButtonItemStyleDone target:self action:#selector(sendAction)];
UIBarButtonItem *button2=[[UIBarButtonItem alloc]initWithTitle:#"Cancel" style:UIBarButtonItemStyleDone target:self action:#selector(cancelAction)];
[toolbar setItems:[[NSArray alloc] initWithObjects:button1, nil]];
[toolbar setItems:[[NSArray alloc] initWithObjects:button2, nil]];
[self.view addSubview:toolbar];
But Buttons are always in disabled form..i donot know why this always happens. i have cleaned my project as well.
NSArray *toolbarItems = [NSArray arrayWithObjects:
button1,button2, nil];
[self.toolbar addsubview:toolbaritems
Add this line of code

UItableview on second page and want to nevigate in third page how it is possible?

I have UITableview in second page then I try to navigate into third page but problem is that my code is not working. Here is the code for both AppDelegate.m file and also SecondViewController.m file,
Plz check the code and give me suggestion what i am doing wrong
SecondViewController.m file code
- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ThirdViewController *third = [[ThirdViewControllerr alloc] initWithNibName: #"ThirdViewControllerr" bundle:nil];
ForthViewController *forth = [[ForthViewControlle alloc] initWithNibName: #"ForthViewController" bundle:nil];
if(indexPath.row==0)
{
[[self navigationController] pushViewController:third animated:YES];
}
if(indexPath.row==1)
{
[[self navigationController] pushViewController:forth animated:YES];
}
In AppDelegate.m file i write the code for Secondviewcontroller in witch using UITableview, also i have initialized the UINavigationController inside AppDelegate.m file.If anyone have idea reply me as soon as possible,
without use UINavigationController inside AppDelegate.m file its possible for UItableview Navigation
AppsDelegate.m file
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[MobileViewController alloc] initWithNibName:#"MobileViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
self.window1=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
self.viewController1=[[HealthCalculatorsViewController alloc]initWithNibName:#"HealthCalculatorsViewController" bundle:nil];
UINavigationController *nav1=[[UINavigationController alloc]initWithRootViewController:_viewController1];
self.window1.rootViewController=nav1;
[self.window1 makeKeyAndVisible];
return YES;
}
Please guide me.
Thanks.
add this in your Appdelegate.h
UINavigationController * navController;
and this in your Appdelegate.m
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
FirstViewController * viewPhone =[[FirstViewController alloc]initWithNibName:#"FirstViewController_iPhone" bundle:nil];
navController=[[UINavigationController alloc]initWithRootViewController:viewPhone];
}
else
{
FirstViewControllerController * viewPad =[[FirstViewControllerController alloc]initWithNibName:#"FirstViewController_iPad" bundle:nil];
navController=[[UINavigationController alloc]initWithRootViewController:viewPad];
}
navController.navigationBar.tintColor = [UIColor blackColor];
self.window.rootViewController=navController;
on your button click
- (IBAction)Btn_Pressed:(id)sender {
SecondViewController * second=[[SecondViewController alloc]init];
if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone)
second = [[SecondViewController alloc] initWithNibName:#"SecondViewController_iPhone" bundle:nil];
else
second = [[SecondViewController alloc] initWithNibName:#"SecondViewController_iPad" bundle:nil];
[self.navigationController pushViewController:lagrangae animated:YES];
}
if you dont want navigation bar just hide it by
[[self navigationController] setNavigationBarHidden:YES animated:YES];

UIPanGestureRecognizer and BringSubviewToFront

I have an app where the user taps a button and the app will instantiate an image layer (UIImageView). I want to make it so that the user can move the selected image layer whichever they tap. After reading some topics here, I've learnt that I can use UIPanGestureRecognizer to move the selected image layer.
- (IBAction)buttonClicked:(id)sender {
imageview = [[UIImageView alloc] initWithFrame:CGRectMake(100, 0, 300, 22)];
UIPanGestureRecognizer *imageviewGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(recognizePan:)];
[imageviewGesture setMinimumNumberOfTouches:1];
[imageviewGesture setMaximumNumberOfTouches:1];
imageview.image = [UIImage imageNamed:#"pinimage.png"];
[imageview addGestureRecognizer:imageviewGesture];
[imageview setUserInteractionEnabled:YES];
[self.view addSubview:imageview];
NSUInteger currentag = [self UniqueTag]; // Assigning a unique integer
imageview.tag = currentag;
}
- (void)recognizePan:(UIPanGestureRecognizer *)sender {
[[[(UITapGestureRecognizer *)sender view] layer] removeAllAnimations];
[self.view bringSubviewToFront:[(UIPanGestureRecognizer *)sender view]];
CGPoint translatedPoint = [(UIPanGestureRecognizer *)sender translationInView:self.view];
if([(UIPanGestureRecognizer *)sender state] == UIGestureRecognizerStateBegan) {
firstX = [[sender view] center].x;
firstY = [[sender view] center].y;
}
translatedPoint = CGPointMake(firstX + translatedPoint.x,firstY + translatedPoint.y);
[[sender view] setCenter:translatedPoint];
}
Now, what I cannot figure out is how to bring the tapped layer to front when there are multiple image layers. It doesn't seem that [self.view bringSubviewToFront:[(UIPanGestureRecognizer *)sender view]] is effective. So how can I revise my code so that the application will bring the tapped layer to the top among others?
Thank you for your help.
A good way to do this is to make a CustomImageView subclass of UIImageView. You attach the UIPanGestureRecognizer to each instance of CustomImageView, and set that instance as it's target. Then the action method triggered by the gesture is implemented in the view itself, so that you can refer to the view with self:
In buttonClicked
MyImageView* imageview = [[MyImageView alloc] initWithFrame:CGRectMake(100, 0, 300, 22)];
UIPanGestureRecognizer *imageviewGesture =
[[UIPanGestureRecognizer alloc] initWithTarget:imageview
action:#selector(recognizePan:)];
In CustomImageView.m
- (void)recognizePan:(UIPanGestureRecognizer *)sender {
[self.layer removeAllAnimations];
[self.superview bringSubviewToFront:self];
CGPoint translatedPoint = [sender translationInView:self];
if([sender state] == UIGestureRecognizerStateBegan) {
self.firstX = [self center].x;
self.firstY = [self center].y;
}
translatedPoint = CGPointMake(self.firstX + translatedPoint.x,
self.firstY + translatedPoint.y);
[self setCenter:translatedPoint];
}
update
Not thinking straight - you can of course do this from the viewController, as you are doing, by accessing the view property of the gestureRecongnizer. Your error is rather here:
- (void)recognizePan:(UIPanGestureRecognizer *)sender {
[[[(UITapGestureRecognizer *)sender view] layer] removeAllAnimations];
You are changing the sender type from UIPanGestureRecognizer to UITapGestureRecognizer. In fact you don't need to do any of that sender typecasting in the body of the method.

I have a UICollectionView and i want to show an image in a Cell, that goes to a normal ViewController. How do i do that?

I have a UICollectionViewController (with a navigation controller) and i want to show an image in a Cell that 'pushes' to a normal ViewController (different by every image). How do i do that?
Seem you want to build photo gallery by UICollectionView.
If use storyBoard, use segue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showDetail"])
{
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex:0];
// load the image, to prevent it from being cached we use 'initWithContentsOfFile'
NSString *imageNameToLoad = [NSString stringWithFormat:#"%d_full", selectedIndexPath.row];
NSString *pathToImage = [[NSBundle mainBundle] pathForResource:imageNameToLoad ofType:#"JPG"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:pathToImage];
DetailViewController *detailViewController = [segue destinationViewController];
detailViewController.image = image;
}
}
If use nib: inside didSelectItemAtIndexPath, use self.navigationController push.
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
NSString *imageNameToLoad = [NSString stringWithFormat:#"%d_full", indexPath.row];
NSString *pathToImage = [[NSBundle mainBundle] pathForResource:imageNameToLoad ofType:#"JPG"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:pathToImage];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
detailViewController.image = image;
[self.navigationController pushViewController:detailViewController animated:YES];
}
Sample code from Apple:
https://developer.apple.com/library/ios/#samplecode/CollectionView-Simple/Introduction/Intro.html
CollecionView tutorial: http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12

Controls disabled after code executed XCode 4.5 iOS 6

I've created an app which uses the following:
SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook
SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter
The code seems to work OK and makes the posts to Facebook and Twitter but then once the posts have been completed and I return back to the app view none of the controls are active and I have to close the app and relaunch for them to work again.
I think I have nested to code incorrectly in the IF statement (posted below), so was wondering if anybody could offer any advice.
I'm very new to Xcode etc so please be patient and kind to me :-)
Thanks in advance
Pete
- (IBAction)postButton:(id)sender
{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *facebook = [[SLComposeViewController alloc] init];
([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]);
{
SLComposeViewController *twitter = [[SLComposeViewController alloc] init];
facebook = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebook setInitialText:[[self statusMessage]text]];
twitter = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[twitter setInitialText:[[self statusMessage]text]];
[self presentViewController:facebook animated:YES completion:nil];
[facebook setCompletionHandler:^(SLComposeViewControllerResult result)
{
NSString *output;
switch (result)
{
case SLComposeViewControllerResultCancelled:
output = #"Action Cancelled";
break;
case SLComposeViewControllerResultDone:
output = #"Post Sucessfull";
default:
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Facebook" message:output delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
[self presentViewController:twitter animated:YES completion:nil];
[twitter setCompletionHandler:^(SLComposeViewControllerResult result)
{
NSString *output;
switch (result)
{
case SLComposeViewControllerResultCancelled:
output = #"Action Cancelled";
break;
case SLComposeViewControllerResultDone:
output = #"Tweet Sucessfull";
default:
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Twitter" message:output delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}];
}
];}
}
}

Resources