Pushing a view controller from an CFCoverFlowView - ios

Hi Im developing an app in which I'm using a third party library called CFCoverFlowView (Can't link It but if you just Google CFCoverFlowView you will find the GitHub site).
What I want to accomplish Is to be able to push septet ViewControllers when the different images is clicked. Im using Storyboard so I would like to use the
instantiateViewControllerWithIdentifier:#""
In the library you get the following line to use when an image is clicked:
- (void)coverFlowView:(CFCoverFlowView *)coverFlowView didSelectPageItemAtIndex:(NSInteger)index;
And i have done this to make sure that it works with UIAlertView:
- (void)coverFlowView:(CFCoverFlowView *)coverFlowView didSelectPageItemAtIndex:(NSInteger)index;
{
if (index == 0)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"0" message:nil delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
if (index == 1)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"1" message:nil delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
if (index == 2)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"2" message:nil delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
if (index == 3)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"3" message:nil delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
if (index == 4)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"4" message:nil delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
}
And that workes, when i click on the separate images i get this (Since this Is my first question here I can't post images or more than 2 links because of my low reputation.)
Image 1 http://i60.tinypic.com/k1e4wz.png
Image 2 http://i59.tinypic.com/1g6lif.png
What I want to do Is when an image is clicked a ViewController with a StoryboardID gets pushed.
When i tried this the app crashes:
- (void)coverFlowView:(CFCoverFlowView *)coverFlowView didSelectPageItemAtIndex:(NSInteger)index;
{
if (index == 0)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main.storyboard" bundle:nil];
UIViewController *ViewController1 = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:#"ViewController1"];
[self.navigationController pushViewController:ViewController1 animated:YES];
}
}
So if anyone could help me It would very appreciated and If anything Is missing or you don't understand my code comment and i will edit the text.

Assumption : You're getting this error;
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Main.storyboard'
Solution :
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];

Is that a typo or are you not pushing the instance of the ViewController you instantiated? You need to push ViewController1:
[self.navigationController pushViewController:ViewController1 animated:YES];

Related

UiAlertView should change ViewController

What is wrong with following code? I will change the viewController, when the text in the alertView is not empty. The problem is, it will change the UiViewController every time, even it is empty.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
if ([[alertView textFieldAtIndex:0].text isEqual:#""]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Error warning" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
else{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"ChangeView"];
[self presentViewController:vc animated:YES completion:nil];
}
}
}
You should do this check instead:
if (![[alertView textFieldAtIndex:0].text.length) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Error warning" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
} else ...

iOS UIAlertView being shown more than once

Hi I have used the following function to call an alert view with a specific message. The NSLogs are being printed only once but alert view is called more than once.
I am using UITabBarController for any additional info.
- (void)showUIAlertWithMessage:(NSString *)message {
NSLog(#"showUIAlertWithMessage called");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Something went wrong!😕😕"
message:message
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}

Change iOS tab view from alert

I have a tabbed application with 2 tab views. I want to change the view from the second tab to the first when the user presses "OK" on an alert view.
The following code snippet works when I use it on an -IBAction button pressed, but it doesn't do anything when I use it inside the alert code:
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];
Why does it not work when used as below, in my SeondViewController.m in my
- (void)viewDidLoad {
[super viewDidLoad];?
UIAlertView *alert =[[UIAlertView alloc]
initWithTitle:#"Camera and Target coincident"
message:msg
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];
I'm just learning this, so anything you can offer would be helpful.
When I use the following code:
if ([ theProjection Trans_Initialise] == 1) {
NSString * msg = nil;
UIAlertView *alertView =[[UIAlertView alloc] initWithTitle:#"Camera and Target coincident" message:msg delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([[alertView buttonTitleAtIndex:buttonIndex] isEqualToString:#"OK"]) {
self.tabBarController.selectedIndex = 0;
}
}
I get the error message on -(void) alertView "Invalid argument type void to unary expression" Am I doing something grammatical, or is it (quite possibly) something I just didn't understand?
First of all, you need a delegate call back from the alert view informing you about the button that was clicked.
Your alert view should be created like this :
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:#"Camera and Target coincident" message:msg delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
Then in your m file implement the function :
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([[alertView buttonTitleAtIndex:buttonIndex] isEqualToString:#"OK"]) {
self.tabBarController.selectedIndex = 0;
}
}

UIActionSheet Delegate Self Warning

Since the introduction of iOS 7, a lot of improvements and changes were made to Objective-C. I've created a UIActionSheet below and assigned the delegate to self so that I could program each button press to complete an action.
- (IBAction)sortButton
{
UIActionSheet *sortSheet = [[UIActionSheet alloc]
initWithTitle:#"Sort By"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:#"Featured"
otherButtonTitles:#"Price", #"Brand", nil];
[sortSheet showInView:self.view];
}
This is the code I use to check against what the user did when they clicked on a specific button in the UIAlertView:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)
{
UIAlertView *dueDateAlert = [[UIAlertView alloc]
initWithTitle:#"Featured"
message:#"This button formats the list for items based on Feature."
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"Ok", nil];
[dueDateAlert show];
}
else if(buttonIndex == 1)
{
UIAlertView *creationDateAlert = [[UIAlertView alloc]
initWithTitle:#"Price"
message:#"This button formats the list for items based on Price."
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"Ok", nil];
[creationDateAlert show];
}
else if(buttonIndex == 2)
{
UIAlertView *subjectAlert = [[UIAlertView alloc]
initWithTitle:#"Brand"
message:#"This button formats the list for items based on Brand."
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"Ok", nil];
[subjectAlert show];
}
}
When I run this code, I get the following Warning: Sending SecondViewController *const_strong to parameter of incomplete type 'id<UIActionSheetDelegate> on the self text in the creation of the UIActionSheet. I'm assuming it's saying that I'm doing something "inefficiently", and I was wondering what needs to change in order for this warning not to appear.
It seems that your class does not confirm to UIActionSheetDelegate protocol.
Check that you have something like
#interface YourClass () <UIActionSheetDelegate>

is possible to remove previous alert view?

i have create two UIAlertView views in one method. Code like below
-(void) alert{
UIAlertView *alert_1 = [[UIAlertView alloc] initWithTitle:#"Message" message:#“Alert 1” delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert_1 show];
UIAlertView *alert_2 = [[UIAlertView alloc] initWithTitle:#"Message" message:#“Alert 2” delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert_2 show];
}
after call this method. iPhone app will appear popup for 2 times.
first appear is alert_1, disappear alert_1 and appear alert_2
after user press ok button in alert_2 thn appear alert_1
should be remove alert_1 when appear alert_2
is possible to remove previous alert view?
Send message - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated to alert1.
UIAlertView *alert_1 = [[UIAlertView alloc] initWithTitle:#"Message" message:#“Alert 1” delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert_1 show];
[alert_1 dismissWithClickedButtonIndex:0 animated:YES];
UIAlertView *alert_2 = [[UIAlertView alloc] initWithTitle:#"Message" message:#“Alert 2” delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert_2 show];
I am not clear about what your requirement is. But from what I understood you want alert_2 to popup first and when clicked on the "OK" button you want to dismiss that alert view and popup alert_1
- (void) alertview
{
alert_1 = [[UIAlertView alloc] initWithTitle:#"Alert 1" message:#"Message" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert_1 setTag:1];
alert_1.delegate = self;
alert_2 = [[UIAlertView alloc] initWithTitle:#"Alert 2" message:#"Message" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert_2 setTag:2];
alert_2.delegate = self;
[alert_2 show];
}
- (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (alertView.tag ==2)
{
[alert_1 show];
}
}
Please note to declare your alert views in your .h file
Get UIAlertView by its tag or #Property and use this [myAlertView dismissWithClickedButtonIndex:-1 animated:YES];

Resources