I have a Tab-Bar Application for this iPhone application I am making. I make a simple button on the 3rd view (3rd tab), and give it an IBAction to give an alert view. When I press build and go, everything works out fine. I go onto the 3rd tab, and I press my button. It simply crashes... Why is this happening? Everything I put in this 3rd tab crashes. I create a simple view controller, and write the class files to start over, but I keep getting the same errors.. Everything works fine on my first tab, where I originally got the first view controller..
P.S> It also says Incomplete Implementation of Class 'ThirdViewController'. I don't know why its there..
If anyone can help me out here, i would greatly appreciate it.
Kevin
It's and UIAlertView, right ?
This class requires the implementation of the protocol UIAlertViewDelegate and the method alertView:clickedButtonAtIndex: to handle the button click, that's why the compiler tell you that it's incomplete.
Anyway i expirienced some problems on the UIAlertView the first time i used it.
My issues was on the otherButtonTitles parameters, the list must be terminated by nil, like this:
[myAlert initWithTitle:#"title" message:#"body " delegate:self cancelButtonTitle:#"cancel" otherButtonTitles:#"ok",#"ignore",#"retry",nil];
Anyway, you can find useful debug about the crash into your console, try to post it here.
Related
I'm looking at a friend's code and not sure how this works. There's a singleton that talks to a web service to download data. The WebServiceObject is a subclass of NSObject. The download comes from a click on the home page which is a UIViewController.
In the WebServiceObject, when something goes wrong, he does:
UIAlertView *alert = [[UIAlertView alloc] init...];
[alert show];
The alert shows. How does that alert show though since the code that executes it is a non-view object? The reason I'm asking is because I want to remove that alert when the network comes back on. Since the network observing is happening in the WebServiceObject, I'm not sure how to access the UIAlertView object. I thought in other code I've done, that I would do something like
[self.view viewWithTag:NETWORK_ALERT_TAG];
or something to that affect. Is this because the view code is in the model code and instead I should change his code to post a notification to the view code to display the alert instead and grab it that way? Thanks a bunch!
UIAlertView’s -show method creates its own window, overlaid on top of the app’s window, in which to display itself; as such, it isn’t part of the app’s view hierarchy. To hide it, you’ll need a reference to the alert view itself, maybe exposed as a property on your WebServiceObject.
It sounds like you want to have the UIAlertView without any buttons, I found this nice tutorial that presents a "Please Wait Alert"
http://mobiledevelopertips.com/user-interface/uialertview-without-buttons-please-wait-dialog.html
I think it will help you achieve what you want, if you don't want the user to be able to dismiss the alert
In my project I show an Alert to the user to indicate an 'empty list'.
Right now, I show it in AppDelegate>applicationDidBecomeActive.
I'm doing this because I want the alert to show if the list is empty
at app startup and when coming out of the background (iOS 4.2 through 5.x).
EDIT:
I use a method in the AppDelegate, and call it with a slight delay, and I still get this notice.
[self performSelector:#selector(checkForNoMessages) withObject:nil afterDelay:1.0];
However, this causes a "wait_fences" notice in the debugger and I'd prefer not to submit to Apple with this notice.
Where is the proper place to put a popup Alert so that it appears:
1) At App startup
AND
2) When the App is coming out of the background?
Do I need the Alert in more than one place?
I recommend writing a method in your AppDelegate or better in your root view controller which shows the message. Maybe with some arguments, so you can reuse it but that's up to you.
If you are following the MVC architecture ask your model about existing entries and trigger the Alert message if necessary. But encapsulate this behavior in a controller as well.
application:didFinishLaunchingWithOptions: and applicationDidBecomeActive: are the places where you want to delegate this task to your controller.
More about iOS Multitasking: https://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html
Edit:
Don't forget that you have to call the methods from the main thread.
And do all startup stuff first.
OK - the problem wasn't where I called the alert, it was because it was in a method. Once I moved the code from a method into applicationDidBecomeActive, all is well.
I have a question or two about using AVFoundationFramework in XCode.
I downloaded AVCamDemo source code. I am trying to leverage the code in my app to replace UIImagePickerController (because it is slow) with the AVFF functionality. However, I cannot figure out how to exit the AVFF code when "Done" button is tapped in the UI. My app will provide the Done button.
Specifically, I need to know:
What do i need to stop the capture session? Just [session stopRunning] ??
My app's ViewController will invoke the AVFF, and will provide the "Done" button in the view controller that I will create for the AVFF functionality. When the user taps the "Done" button, I need to stop the capture process and exit back to my app. I am not sure how this can be done.
Any help will be highly appreciated.
Regards, Sam.
Yes. Although you may also want to ensure you turn the video torch off if you had turned it on, and if you called lockForConfiguration on the device you should be sure to unlock it.
There is no "exiting". If you presented your view controller using presentModalViewController:animated:, use dismissModalViewControllerAnimated:. If you pushed it onto a UINavigationController, pop it back off. If you did it some other way, dismiss it in the way appropriate for that method.
regarding your question on AVFoundationFramework:
I don't exactly understand what you are not succeeding to do. Some general options:
[session stop] will stop capturing.
You can play with the AVCaptureVideoPreviewLayer layer - that's what actually shows the camera preview.
All the ui code is in AVCamViewController - so you can just pop it from the stack, or remove it from superview - which ever is correct in your code.
If these don't help, please try to elaborate further on the problem, and perhaps supply some code.
Cheers,
Oded.
I think this scenario should be weird one but i am stuck up with this.
I am having a view lets say View1, which will show one or more alertviews.Alerts are stacked one above the other if they are untouched.
The problem comes here.
If i click the top most alert ,it should take me to a complete new view lets say View2. And it does. Now i am getting the remaining alerts still shown in View2. I do not want this to happen . How can i auto dismiss the pending alerts created from View1 which are currently being shown in View2 ?
Any help or any idea is really appreciated..
Thanks
Try this,
UIAlertView *autoAlertView = [[UIAlertView alloc] initWithTitle:#"Auto-dismissed Alert" message:#"This alert will be dismissed in 5 seconds." delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
[self performSelector:#selector(dismissAlert:) withObject:autoAlertView afterDelay:5];
[autoAlertView show];
[autoAlertView release];
-(void)dismissAlert:(UIAlertView *)alert {
[alert dismissWithClickedButtonIndex:0 animated:YES];
}
Not quite the answer to your question that you wanted, but...
Why do you have so many alerts? It sounds like you might be overusing them. Apple is quite clear in its Human Interface Guidelines about how you should use UIAlerts:
Avoid creating unnecessary alerts.
These alerts are usually unnecessary
if they:
Merely increase the visibility of some information, especially
information that is related to the
standard functioning of your
application.
Instead, you should design an
eye-catching way to display the
information that harmonizes with your
app’s style.
Update users on tasks that are progressing normally.
Instead, consider using a progress
view or an activity indicator to
provide progress-related feedback to
users (these methods of feedback are
described in “Progress View” and
“Activity Indicator”).
Ask for confirmation of user-initiated actions.
To get confirmation for an action the
user initiated, even a potentially
risky action such as deleting a
contact, you should use an action
sheet.
Inform users of errors or problems about which they can do nothing.
Although it might be necessary to use
an alert to tell users about a
critical problem they can’t fix, it’s
better to integrate such information
into the UI, if possible. For example,
instead of telling users every time a
server connection fails, display the
time of the last successful
connection.
If you're overusing alerts: don't. Then your original question may become moot.
You can dismiss the other UIAlertViews programmatically using:
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
You'll need to store a reference to them at creation to do this.
Thanks, guys! I wrote my own substitute for UIAlertView. I'm putting halftransparent UIView with frame (0, 0, 320, 480) to avoid user interaction while my custom alert still says "Please wait", and above this background view I'm putting this custom alert which is just basic UIView with UIActivityIndicatorView on it
P.S. Don't judge me for my english, i'm russian
I can't find any documentation to confirm this, but it appears that you can only call the method stringByEvaluatingJavaScriptFromString in overridden methods from a UIWebView delegate. Can anyone confirm this?
Here's what I've tried. I setup a button on a view, link it to a method on my viewcontroller, and make sure it works fine. My view has a UIWebView control on it as well. If I run the project on the simulator or on the iPhone, there are no issues. Then I add this code to the button's method.
[theWebView stringByEvaluatingJavaScriptFromString:#"alert('Hi there!');"];
When I run the project, I can click the button and see the 'Hi there' prompt and I can click OK to dismiss it. Usually 4-5 seconds later the simulator crashes. I occasionally see the "__TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION__" error, but not consistently; sometimes there's no error. It also doesn't always crash the first time. Sometimes I go to another page, and then try it again, and it crashes.
If I put the same code in the webPageDidFinishLoad event it works fine. But I'd like the code to be called when the user demands it so that event doesn't suit my needs.
I'm open to a workaround if you have any ideas? Thanks in advance!
I still don't know the exact reason this didn't work, but I found I could rewrite my code to get called during the UIWebView delegate methods instead.