I need this small PDFMaker code in my larger code project, which is almost done expect for the PDFMaker. My larger project is all done in storyboard, and the PDFMaker in xib. I didn't see how you could do them both in the same project. I used the Apple "Converting to Storyboards Release Notes" to convert the PDFMaker from xib to storyboard. Pretty easy and straightforward. However, I can't get either the didClickMakePDF or didClickOpenPDF selectors to work. I keep getting the message
unrecognized selector sent to instance
and a thread pointer to the Main.m file
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MTAppDelegate class]));"
line. I'm new to coding and have been working on this for over 20 hours with no success. All the actions and outlets seem to be set up fine in both the .h, .m, and storyboard files. Could somebody please help me to fix this, or suggestion a different approach to be able to use this PDFMaker code in a storyboard-based project?
Here is my .h file:
#import <UIKit/UIKit.h>
#import "ReaderViewController.h"
#interface MTViewController : UIViewController <ReaderViewControllerDelegate>
- (IBAction)didClickMakePDF:(id)sender;
- (IBAction)didClickOpenPDF:(id)sender;
#end
Here is the relevant part of the .m file for the didClickMakePDF:
- (IBAction)didClickMakePDF:(id)sender {
[self setupPDFDocumentNamed:#"NewPDF" Width:850 Height:1100];
[self beginPDFPage];
CGRect textRect = [self addText:#"This is some nice text here, don't you agree?"
withFrame:CGRectMake(kPadding, kPadding, 400, 200) fontSize:48.0f];
CGRect blueLineRect = [self addLineWithFrame:CGRectMake(kPadding, textRect.origin.y + textRect.size.height + kPadding, _pageSize.width - kPadding*2, 4)
withColor:[UIColor blueColor]];
UIImage *anImage = [UIImage imageNamed:#"tree.jpg"];
CGRect imageRect = [self addImage:anImage
atPoint:CGPointMake((_pageSize.width/2)-(anImage.size.width/2), blueLineRect.origin.y + blueLineRect.size.height + kPadding)];
[self addLineWithFrame:CGRectMake(kPadding, imageRect.origin.y + imageRect.size.height + kPadding, _pageSize.width - kPadding*2, 4)
withColor:[UIColor redColor]];
[self finishPDF];
}
Here is the Main.m file:
#import <UIKit/UIKit.h>
#import "MTAppDelegate.h"
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MTAppDelegate class]));
}
}
Your error messages contain the selector didClickMakePDF (with no colon, so no argument) but your code uses the selector didClickMakePDF: (with a colon, so expecting one argument). These are different selectors.
In your storyboard, you need to delete the connections from your buttons to those (incorrect) actions and create connections from the buttons to the correct actions.
UPDATE
Sometimes the storyboard editor (“Interface Builder” or IB) gets out of sync with the source code, remembering methods that you've deleted or ignoring methods that you've created. Here are some things to try, in increasing order of brutality:
Make sure all files are saved. (Command-Option-S saves all files.)
Close all files in the project window by pressing Control-Command-W repeatedly, until the editor window is blank.
Quit and restart Xcode.
Clean your build folder by pressing Option-Shift-Command-K.
Delete your Derived Data folder for the project. Close your project, then open the Organizer window and click on the Projects tab. Click on your project in the left-side list. Then click the Delete… button to the right of the Derived Data line in the right-side pane.
UPDATE 2
When you delete a resource file (like a xib file) from your app and then run the app, Xcode doesn't delete the resource file from the app installation on the simulator or device. You need to delete the app entirely from the simulator or device (in the usual way, by making the icons wiggle and then tapping the X button) to remove the obsolete xib file.
Related
I need to have a text part in my iOS application (in Objective C), with different names written. Each name must be linked to a view with the person's informations.
I don't know how to do that, what to use to be able to generate multiple links in one text, and link each name do the right action. So when I click on the link it should send the name I clicked on to required action.
Anyone knows how to do that with UIViews ? Or UILabels ? or anything..
Also, whenever I put a UIView in my View, it takes longer to load, do you know why ?
Thanks.. Hope that was clear enough !
HermyKa
You can use RTLabel for that,
Add this library in your code and than follow this step,
In .h file add this code
//Import RTLabel
#import "RTLabel.h"
// Add delegate
#interface ViewController : UIViewController<RTLabelDelegate>
#end
And in .m file
- (void)viewDidLoad {
RTLabel *label = [[RTLabel alloc] initWithFrame:CGRectMake((self.view.frame.size.width-262)/2, (self.view.frame.size.height-203)/2, 262, 203)];
label.delegate = self;
// You have to create link for each name
NSString *searchString = #"Dilip Dev Ram";
}
//RTLabel Delegate Method
- (void)rtLabel:(id)rtLabel didSelectLinkWithURL:(NSURL*)url
{
//When user click on one of the name this method will called and url will return the name which user has tapped. You can add condition on name that which view will display.
NSLog(#"did tap on name %#", url);
}
You can use the set of the UILabels with gesture recognizer connected to each. Or the set of UIButtons.
http://www.raywenderlich.com/104744/uigesturerecognizer-tutorial-creating-custom-recognizers
I am working on an app using RTMP/RTSP links to broadcast/play live audio/video.As iOS devices support HTTP , but my requirement is to play RTMP/RTSP Links.
I want to create my custom player using FFMpeg framework.I have searched over internet , ried many solutions but did not find any solution.
there's a Xcode project based on ffmpeg. It's possible to play RTSP links. Have a look at it:
https://github.com/durfu/DFURTSPPlayer
If you want to know more about RTSP, I can highly recommend you the following link:
https://www.rfc-editor.org/rfc/rfc2326
Here is an overview of current solutions for rtsp on iOS:
https://gist.github.com/oc2pcoj/e55795550984d205d109
I use ijkplayer at current project for playing video stream from IP-cam. It works fine.
To play an rtsp stream on iOS using ffmpeg I recommend https://github.com/teocci/RTSP-Client-iOS
For reference, here is an Objective-C interface to RTSP-Client-iOS/FFMpegDecoder/RTSPPlayer.m based on RTSP-Client-iOS/RtspClient/ViewController.swift;
//
// ViewController.h
//
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIImageView *imageViewInstance1;
#end
//
// ViewController.m
//
#import "ViewController.h"
#import "RTSPPlayer.h"
RTSPPlayer *rtspPlayer;
int frameIndex;
NSTimer *timerRefresh;
#define CAMERA_RTSP_ADDRESS "rtsp://..."
#define CAMERA_FPS (30.0)
#define TIMER_INTERVAL_SECONDS (1.0/CAMERA_FPS)
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString* address = #CAMERA_RTSP_ADDRESS;
rtspPlayer = [[RTSPPlayer alloc] initWithVideo:address usesTcp:false];
rtspPlayer.outputWidth = 640;
rtspPlayer.outputHeight = 480;
[rtspPlayer seekTime:0.0];
timerRefresh = [NSTimer scheduledTimerWithTimeInterval:TIMER_INTERVAL_SECONDS target:self selector:#selector(run:) userInfo:nil repeats:YES];
}
-(void) run:(NSTimer *) timer
{
if(![rtspPlayer stepFrame])
{
[timerRefresh invalidate];
[rtspPlayer closeAudio];
}
UIImage* uiImage = rtspPlayer.currentImage;
_imageViewInstance1.image = uiImage;
frameIndex++;
}
#end
To create an ImageView object in the user interface (_imageViewInstance1);
Project Navigator (left pane) - [INSERTAPPLICATIONNAME]
Open Main.storyboard
Select View Controller Scene - View Controller - View
Select the Library button (top right: circle with inside square)
Search for 'Image View'
Drag and drop a new View Image Object into View Controller Scene - View Controller - View (adjacent 'Safe Area')
Create an outlet connection for the new Image View object
Select the Assistant Editor button (top right: two intersecting circles)
Select file ViewController.h in the Project Navigator
If necessary hide the left and right panes to create more space (top right: blue box with left vertical bar, blue box with right vertical bar)
hold the Ctrl key and drag the new image view object to the ViewController.h file (immediately below #interface ViewController: UIViewController) - name the object reference as imageViewInstance1
In Xcode 5.0.2
I create a blank single view app for iPhone,
then add a "male.png" image to the project,
drag a UIImageView to the storyboard
and finally add the following code to the viewDidLoad:
_imageView.image = [UIImage imageNamed:#"male.png"];
This works well:
Then I add the 4 files from JMImageCache project and change the ViewController.m to:
#import "ViewController.h"
#import "JMImageCache.h"
static NSString* const kAvatar = #"http://gravatar.com/avatar/55b3816622d935e50098bb44c17663bc.png";
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[_imageView setImageWithURL:[NSURL URLWithString:kAvatar]
placeholder:[UIImage imageNamed:#"male.png"]];
}
#end
Unfortunately, this results in app crash with the error message Thread 1: EXC_BAD_ACCESS:
At his webpage Jake Marsh (the author of JMImageCache) notes:
JMImageCache purposefully uses NSString objects instead of NSURL's to make things easier and cut down on [NSURL URLWithString:#"..."] bits everywhere. Just something to notice in case you see any strange EXC_BAD_ACCESS exceptions, make sure you're passing in NSString's and not NSURL's.
But (as an iOS programming newbie) I don't understand, what exactly does Mr. Marsh mean - since his file UIImageView+JMImageCache.m declares the 1st argument for the public method as NSURL:
- (void) setImageWithURL:(NSURL *)url placeholder:(UIImage *)placeholderImage {
[self setImageWithURL:url key:nil placeholder:placeholderImage];
}
Is the note maybe outdated and how could I fix my app?
That's a bug in JMImageCache. setImageWithURL:key:placeholder:completionBlock: calls itself, exhausting the stack.
To work around the bug, call the longer form of the method:
[_imageView setImageWithURL:[NSURL URLWithString:kAvatar]
key:nil
placeholder:[UIImage imageNamed:#"male.png"]
completionBlock:nil
failureBlock:nil];
Or, use an older version of the library (e.g. 0.4.0). Looks like the bug was introduced in 1af09be78a.
I have the next code:
- (void)func
{
MyViewController *ctrl = [MyViewController new];
[ctrl doSmth];
[self presentViewController:ctrl animated:NO];
}
//------------
- (void)doSmth
{
CGRect *rect = self.view.frame;
// Do something with rect
self.view.frame = rect;
}
Ok, I know, that when -[UIViewController view] is equal to nil then it's being created. And this code did work before my changes (only buttons and labels visibility, nothing extraordinary) and now it throws SIGABRT on self.view, it looks like it cannot be created. Suddenly. If I revert my changes, all work like a magic. And even if I won't call this function it'll crash on presenting and in Summary it'll show that view = 0x00000000.
I've got only one question: WAT?
I've found the error.
After XCode's “refactoring” (renaming some IBOutlets) old outlets had been marked with the ! sign but not removed and nothing XCode told me about it.
What I mean by !-s, is Interface Builder showing not valid outlets with an icon. Not valid outlet means that you have a connection between a view and a property / instance variable that does not exist. So when the NIB will be loaded in runtime, the application will crash, because there are no such property / instance variable.
So if you run in such error, you should either remove the outlet, or add the property / instance variable with the same name to class which you have linked the XIB to (usually a File's Owner).
I'm doing a short project just to experiment writing without the use of nib files (personal interest only, don't plan on never using nibs!).
I have my app controller set up as NSApp's delegate. Under -(void)applicationDidFinishLaunching:(NSNotification *)aNotification, I attempt to initialize the interface.
AppController.h:
#import <Cocoa/Cocoa.h>
#import <QTKit/QTKit.h>
#interface AppController : NSObject {
NSWindow* mainWindow;
QTMovieView* movieView;
QTCaptureSession* mainSession;
QTCaptureMovieFileOutput* output;
QTCaptureDeviceInput* video;
QTCaptureDeviceInput* audio;
}
+ (void)initialize;
- (id)init;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
#end
Method in AppController.m
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
//Proceed to initialize the entire interface:
mainWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(500, 300, 700, 500)
styleMask:(NSTitledWindowMask|NSClosableWindowMask|
NSMiniaturizableWindowMask|NSResizableWindowMask)
backing:NSBackingStoreBuffered
defer:NO];
[mainWindow setTitle:#"Record a movie!"];
/*movieView = [[QTMovieView alloc] initWithFrame:NSMakeRect([[mainWindow contentView] bounds].origin.x + 5,
[[mainWindow contentView] bounds].origin.y + 30,
[[mainWindow contentView] bounds].size.width - 10,
[[mainWindow contentView] bounds].size.height - 35)];*/
[[mainWindow contentView] addSubview:movieView];
[mainWindow makeKeyAndOrderFront:NSApp];
}
The part commented out is the origin of the 1 error that doesn't appear in the text editor, only in the "build" panel:
<pre> ".objc_class_name_QTMovieView", referenced from:
literal-pointer#_OBJC#_cls_refs#QTMovieView in AppController.o
symbol(s) not found
collect2: Id returned 1 exit status
There seems to be a problem with alloc/init'ing an instance here. I can declare a new one just fine, i.e. QTMovieView *test; and nothing complains. I've also found that it does the same thing with all the other QT classes when I try to alloc/init them. However, I was able to alloc/init NSWindow just fine. The framework is in my project and as you can see in my .h file, I included QTKit.
Anyone know what's going on?
The error you're getting is a linker error -- the linker (ld) can't find the framework object code for the QTMovieView class. Therefore, you haven't included the QTKit framework in your project. If you think you have, then something about it isn't set up properly.