implementing TTThumbsViewController on a UIViewController? - uiviewcontroller

Im trying to implement add TTThumbsViewController as a subview of UIViewController but the app is crashing. Here you see the code-
.h file-
#import <UIKit/UIKit.h>
#import <Three20/Three20.h>
#import <Three20UI/UIViewAdditions.h>
#import "MockPhotoSource.h"
#interface photos : UIViewController <NSXMLParserDelegate, TTThumbsViewControllerDelegate>
{
TTThumbsViewController *photoSource;
...........
}
.m File-
- (void)viewDidLoad {
// parsing a feed
[self parseXMLFileAtURL:#"http://feed203.photobucket.com/albums/aa15/vikysaran/Worst%20Parents/feed.rss"];
NSMutableArray *arr = [[NSMutableArray alloc]init];
for (int i=0; i < [stories count];i++) {
[arr addObject:[[[MockPhoto alloc] initWithURL:[[stories objectAtIndex:i] objectForKey:#"fullimageurl"] smallURL:[[stories objectAtIndex:i] objectForKey:#"thumburl"]
size:CGSizeMake(960, 1280)] autorelease]];
}
photoSource = [[[MockPhotoSource alloc] initWithType:MockPhotoSourceNormal title:nil photos:[NSArray arrayWithArray:arr] photos2:nil]autorelease];
// till here the code is working fine if i am not using uiviewcontroller
NSLog(#"mockphoto%#", arr);
[self.view addSubview:photoSource.view];// adding to uiview
}
here is the error displays-
-[MockPhotoSource view]: unrecognized selector sent to instance 0x6924ca0
2011-09-22 13:07:07.375 JesonTerry[1969:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MockPhotoSource view]: unrecognized selector sent to instance 0x6924ca0'
Please anybody help. i am totally confused where i am wrong...

your view controller has to be a type TTThumbsViewController and not a UIViewControler for starters.. Check the TTCatalog app in the samples folder

Related

UIWebView opening the camera and images when a button is clicked

I am currently wrapping a webApp up as an app. With in the web app there is a button that when clicked automatically asks if you want to go to the camera of the stored images and when selected will upload the image for you. In the web app from the phone browser this works as expected.
Now I have wrapped the webApp up in a UIWebView this function no longer works. It actually appears to close the UIWebview when selecting either of the above options. Does anyone know what the procedure is to get this to work through the UIWebView.
Do I have to give permission? Or is there more to it like detecting the HTML when the button is clicked and handling it from the UIWebView.
The HTML on the button looks like this.
<input type="file" required id="file" name="file" accept="image/*" multiple>
ADDED CODE
WebViewController.h
#import <UIKit/UIKit.h>
#interface WebViewController : UIViewController <UIWebViewDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate>
{
UIViewController *viewController;
}
........
WebViewController.m
#import "WebViewController.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import "AppDelegate.h"
#end
#implementation WebViewController
- (void)viewDidLoad
{
[super viewDidLoad];
viewController = [[UIViewController alloc] init];
NSString *fullURL = self.mainURL; // get this from defualts - have removed code for this
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_viewWeb loadRequest:requestObj];
ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];
[lib enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
NSLog(#"%i",[group numberOfAssets]);
} failureBlock:^(NSError *error) {
if (error.code == ALAssetsLibraryAccessUserDeniedError) {
NSLog(#"user denied access, code: %i",error.code);
}else{
NSLog(#"Other error code: %i",error.code);
}
}];
}
-(void)webViewDidStartLoad:(UIWebView *)viewWeb
{
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}
- (void)webViewDidFinishLoad:(UIWebView *)viewWeb
{
}
//Note: I check to make sure the camera is available. If it is not (iPod touch or Simulator) I show the photo library instead.
-(void) showCamera
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else
{
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
imagePicker.delegate = self;
[viewController presentViewController:imagePicker animated:YES completion:nil];
}
//Here we intercept any time the webview tries to load a document. When the user hits our "showcamera: url" we go to work.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:
(UIWebViewNavigationType)navigationType
{
if ([request.URL.scheme isEqualToString:#"myApp"])
{
if ([request.URL.host isEqualToString:#"myFunction"])
{
[self showCamera];
}
return NO;
}
return YES;
}
//After the imagepicker has done it's thing, we pass the data back to the webview to be displayed.
//If we wanted to be fancy here, we could have done this via Javascript so we could dynamically insert an image without reloading the page.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[viewController dismissViewControllerAnimated:YES completion:nil];
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData *imageData = UIImageJPEGRepresentation (image, 0.5);
NSURL *tmp = [NSURL URLWithString:#"ignore"];
[_viewWeb loadData:imageData MIMEType:#"image/jpeg" textEncodingName:#"UTF-8" baseURL:tmp];
}
#end
I have removed some code that was irrelevant
I have managed to fix the issue and it goes way back to bug that was found in iOS 8 that still hasn't been fixed. Its to do with how the UIWebView is being presented.
Adding this code fixed it.
-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
{
if ( self.presentedViewController)
{
[super dismissViewControllerAnimated:flag completion:completion];
}
}
For any one else confused or struggling with this Note that you do not need to start messing around with UIImagePicker or UIWebView delegates. Your web view should take care of opening the camera library or camera. This was a real pain of an issue so hopefully this may help others in my position. you can also see THIS Question as this is where i got my answer from. Thanks Andrey for helping too
As an alternative you can try to use UIWebViewDelegate's method webView:shouldStartLoadWithRequest:navigationType: to catch custom events:
In your HTML:
Do something
<button onclick="window.location.href='myApp://myFunction'">Do some action</button>
And then:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([request.URL.scheme isEqualToString:#"myApp"]) {
if ([request.URL.host isEqualToString:#"myFunction"]) {
// do something
}
return NO;
}
return YES;
}

Pass Variable (cookie) from local html to UILabel - iOS

I wanted to know how I could go about passing a Variable (cookie) in a local HTML file in my iOS App, and pass what the cookie says onto a UILabel. Here is what the HTML code is. I need to pass this message into a UILabel
<script language="javascript">setCookie('Test','You Sir have succeeded. Congratulations.', 300);
</script>
And here is my updated code for iOS app
Header File:
import
#interface ViewController : UIViewController {
IBOutlet UIWebView *webView;
IBOutlet UILabel *mylabel;
}
#end
Main File
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"DTPContent/cookietest" ofType:#"html"]isDirectory:NO]]];
[super viewDidLoad];
NSString *myCookie = [self->webView stringByEvaluatingJavaScriptFromString:#"getCookie('Test')"]; self->mylabel.text = myCookie;
}
#end
Thank You in Advance!
Assuming you already have a javascript function to get the cookies, like that, you can simply execute the javascript with webview's method stringByEvaluatingJavaScriptFromString , get it's returned string and set it in a UILabel.
It will be something like this:
NSString *myCookie = [self.webView stringByEvaluatingJavaScriptFromString:#"getCookie('Test')"];
self.mylabel.text = myCookie;

-[UIView setShowsFPS:]: unrecognized selector error

I need to open a ViewController when a UIButton was press , for doing that I use the following
code :
NSString * storyboardName = #"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"ViewController"];
[self presentViewController:vc animated:YES completion:nil];
when it take the final line
[self presentViewController:vc animated:YES completion:nil];
it give me the following error:
-[UIView setShowsFPS:]: unrecognized selector sent to instance 0x9bd5610 2013-07-16 14:40:52.728 ChainZoo[3026:a0b] * Terminating
app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[UIView setShowsFPS:]: unrecognized selector sent to instance
0x9bd5610'
Anyone knows the error?
thanks in advance!!
On the storyborad, select your ViewController's view and click "Show the identity inspector" (third little tab on the top right side).
You'll see Custom Class textview.
Write "SKView" and try to run again.
You should init your VC's view as a SKView.

Trouble with new View Controller called from a UITextField Xcode

In the current App that I am writing, I have a UITextField that has a link in it. So I want to call a new View Controller instead of Safari. I can have it open in Safari, but I don't want the user to leave my App. I have done some research and am doing the following.
I made a new file called MyApplication and placed the following inside the .m file to override openURL
#import "MyApplication.h"
#implementation MyApplication
- (BOOL)openURL:(NSURL *)url
{
if ([self handleOpenURL:url])
return YES;
else
return [super openURL:url];
}
- (BOOL)handleOpenURL:(NSURL *)url
{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:#"71"];
[self presentViewController:vc animated:YES completion:nil];
return YES;
}
#end
In the attributes inspector under View Controller I called the Title 71. I also called the storyboard ID and restoration ID 71 just to be sure! In the main.m file I have replaced the third nil with #"MyApplication" as you can see.
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, #"MyApplication", NSStringFromClass([AppDelegate class]));
}
}
However, the App fails to build because in the method handleOpenURL I am getting an error on the line
[self presentViewController:vc animated:YES completion:nil];
It says No visible #interface for 'MyApplication' declares the selector 'presentViewController:animated:completion:' All the samples and questions I have seen are using the deprecated method presentModal but Xcode tells me to use this newer method presentViewController. So does anyone know what I am doing wrong? I must be missing something, but I can't for the life of me find out. Thanks in advance on any insight to this matter!!!
May be you're missing the :
#import <UIKit/UIKit.h>

A view can only be associated with at most one view controller at a time. UIViewControllerHierarchyInconsistency

I have this problem on iOs6 on iOs5 works just fine.
this loads the LoginView
- (void)viewDidLoad {
if(!currentView ){
currentView = [[Login alloc] init];
}
self.view = currentView.view;
[super viewDidLoad];
}
And this is on AppDelegate
if (!mvc) {
mvc = [[[mainViewController alloc] init] autorelease];
}
[window addSubview:mvc.view];
[window sendSubviewToBack:mvc.view];
[window makeKeyAndVisible];
2013-01-15 18:02:33.137 fodboldfabrikken[5412:19d03] * Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View > is associated with . Clear this association before associating this view with .'
* First throw call stack:
(0x2097012 0x1c78e7e 0x2096deb 0xa90309 0xb275ac 0xb23a90 0x3206 0xb23817 0xb23882 0x2b49 0xa3f7b7 0xa3fda7 0xa40fab 0xa52315 0xa5324b 0xa44cf8 0x2aafdf9 0x2aafad0 0x200cbf5 0x200c962 0x203dbb6 0x203cf44 0x203ce1b 0xa407da 0xa4265c 0x2a4d 0x2985 0x1)
libc++abi.dylib: terminate called throwing an exception
You are not allowed to have a controller inside another controller which is what you are doing here mvc = [[[mainViewController alloc] init] autorelease];