How to show a NSObject as a UIView? - iphone

I read on StackOverflow that to create a messaging speech bubble, the TTSpeechBubbleShape class is highly recommended.
Speech Bubble in iOS SDK using Objective-C
However, this class is derived from a custom NSObject class, so I have no idea how to turn this NSObject and add it into one of the cells of my custom UITableView class?
So, how does one turn a NSObject into a UIView? (Or at least show a NSObject as part of a UIView)
Thanks from a first time iOS app developer.
More info on the class:
http://api.three20.info/interface_t_t_speech_bubble_shape.php
https://github.com/facebook/three20/blob/master/src/Three20Style/Headers/TTSpeechBubbleShape.h
https://github.com/facebook/three20/blob/master/src/Three20Style/Sources/TTSpeechBubbleShape.m

Those bubble classes just prepare a path. A path can be drawn in a CGContext. You cannot draw a UIObject in any way. Learn the basics of cocoa touch... read the documentation.
A more easy way for your bubbles is a single resizable image like in this answer: https://stackoverflow.com/a/11196243/407488

Related

what is the difference between NSObject and UIViewController

i am new to iphone development and i am going through tutorial and some sample.
i want to know what is the difference between NSObject and UIViewController class and how we will come to know which class we should use.
some are written in NSObject and some are in UIViewController.
From Wikipedia, a basic overview of object-oriented programming:
Object-oriented programming (OOP) is a
programming paradigm using "objects" –
data structures consisting of data
fields and methods together with their
interactions – to design applications
and computer programs. [...] An object-oriented program will usually contain different types of objects, each type corresponding to a particular kind of complex data to be managed or perhaps to a real-world object or concept such as a bank account, a hockey player, or a bulldozer.
In Objective-C, all Objects are based upon NSObject. Just take this at face value for now. If you want to use an Object, it's going to be based on NSObject. So, unless you're using an int or a float, you're likely using something that's based on NSObject.
NSObject in-and-of-itself, doesn't really supply any functionality. It's your 'starting place' or 'blank slate' for an Object.
You might build an Object definition which is used to represent an Animal, like this:
#interface Animal : NSObject { }
#property (assign) int age;
- (Animal*)mateWith:(Animal*)lover;
#end
In this example we've described a basic Animal. This class basically does two things; knows the age of the Animal, and can mate with another animal to produce an Animal offspring.
You'll notice in that example that we based our Object definition on NSObject.
Now, say we want to create a definition for a Human; well, a Human is, and always will be, a subset of all Animals. So, we can re-use all of the logic in the Animal class definition to create a Human definition - and we might do so like this:
#interface Human : Animal { }
- (void)lie;
#end
In this example, we've created a new definition for a type of Object called "Human". We only defined one thing: a method which gives our class the ability to lie - except we'll also get the ability to mate because we're based on "Animal", and "Animal" already describes how to mate.
Getting to your question:
UIViewController contains a BUNCH of logic for doing some very complex tasks. Most of that logic is part of the Cocoa Touch framework.
If you're making an "Animal" class, you don't need to know how to respond to user input from the screen, you don't need to know how to manage a UIView, you don't need to keep track of parentViewControllers, etc. So, basing our Animal class on UIViewController would be silly. This is when NOT to use UIViewController.
Now, if you've making a user interface screen on the iPhone, and you want to perform some routine when the user clicks on a button - then you DO need all of the UIViewController stuff, so you'd subclass that.
I can understand why, if you're not coming from an Object Oriented Programming background, you might be confused about this. It seems like most of the things you'd need to create ARE UIViewController subclasses. However, as you explore the world of OOP, you'll discover that not only are Objects something someone else wrote that you can use - but they are things you'll want to create from the ground up to accomplish things you used to do procedurally.
Best of luck on your exciting journey.
I'd highly recommend you take a trip to your local Barnes and Noble or head over to Amazon.com and pick up some books on the topic - if you have a friend who already knows OOP a good mentor is much faster than learning yourself.
Don't forget, on the iPhone, you'll have to deal with memory management as well. This is a sticking point for a lot of people - and causes a lot of headaches if you don't follow the rules. Learn them early and you'll be served well.
Hope that helped,
Cheers.
Sources:
http://en.wikipedia.org/wiki/Object-oriented_programming
UIViewController is a subclass of UIResponder which is itself a subclass of NSObject which is a root class (i.e. not a subclass of anything).
This means that any method for NSObject may be called on UIViewController, but not conversely. If you look at the UIViewController Class Reference, it has all of the properties and methods available to you if you use this class. In addition, you automatically get all of the methods for an NSObject (listed in the NSObject Class Reference).
I use a UIViewController for every view that I maintain. I almost never use an object directly as an NSObject, though I often subclass NSObject and I never subclass UIViewController. But this is just me.
I recommend you take a look at Apple's View Controller Programming Guide to see what benefits using a UIViewController offers.
NSObject means it inherits the ObjectProperties only.It doesn't have view.But UIViewcontroller is having the view itself.It can control the views also.
When you don't want a view then you can use the NSObject.If you need viewcontroller or view then you can use the UIViewController.
NSObject is the super class in obj_c and UIViewcontroller is sub class to NSObject.UIViewcontroller inherits properties from UIResponder and this class inherits from NSObject class...

Why not UIImage itself but UIImage view

I'm learning to develop apps for Iphone. I follow a book by Apress which I find very useful. But as nothing is perfect some issues are not well described and just skipped.In one of the applications I have to assign five images to each of the five components of a pickerview. But my question is why do/can not we use an instance of UImage itself but UIImageView to display on the picker.
As in above question you are asking why we can not use UIImage instead of UIImageView as component for UIPickerView.
UIImage is subclass of NSObject class, If we talk in terms of M-V-C its a M(model). and model in itself is nothing until its used.
UIImageView on the other hand is subclass of UIView which stands for V(view) in M-V-C so it uses your model for its contents.
So, they are two different things, not alternate. Also, if you go through UIPickerView's class documentation then you will find that it has method
- (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component
that configures view for specified row component. so it meanse we need view(UIImageView) and not the model class(UIImage). here for component you can return subclass of UIView.
Please refer apple's documentation.
Thanks,
You need a frame to place your photo, similarly You need UIImageView as place holder to place UIImage.
UIImage is just an Image loaded from file. View is able to handle touch events and only Views are displayed.

iPhone Deck Game interface

I wrote the code of a card game .. but now it's time todo the graphic and Interface
What's the best approach to represent a card ??
a) CALayer
b) UIView
c) UIButton
Which one is best to animate and receive user touches???
What do you recommend??
Thanks in advance
GeekGameBoard is older Apple-provided example code for card and board games that implements the UI in CALayers. Another user modified it to run on the iPhone so it might be helpful code for you to look at. The modified project is on bitbucket.
as UIButton is subclass of UIView, there's no so much difference in both of them.
If you need only 'clicks' handling, you can choose button, if you will need to override touchesBegan/touchesMoved you should override UIView instead UIButton.
A UIView subclass would probably be your best choice. You can easily receive touch events from the user, and UIView allows you to do simple animations easily.

How to creat UITable, UIButton, UILable, UIImage, UIText, UISlider, UINavigationBar, UITabBar programiticly?

I'm new with the iphone programming and I'm trying to know how to create all of these (UI's) without using the IB, so I'm only asking for the code lines that will create each one of these.
The best way to figure this out is to read through the documentation for each of these classes. Some which are subclasses of UIView can be instantiated with -initWithFrame:, for example.
i am new to iphone/ipad programming , i fallowed below links to create views programmatically... i think these are helpful to u also >>
To create UIButton,UILabel,UIImage,UITextField programmatically
http://www.edumobile.org/iphone/iphone-programming-tutorials/implement-uibutton-uitextfield-and-uilabel-programmatically-in-iphone/
To create UITableView Programatically
http://thesdkblog.com/2011/05/how-to-setup-a-uitableview-programmatically/
To create UINavigationController and UITabbarController Programmatically
http://codenugget.org/how-to-embed-a-navigation-controller-inside-a
http://www.xdracco.net/howto-implement-uinavigationcontroller-uitabbarcontroller-programmatically/
Thanks u..
I've Noticed that a lot of people viewed this question, so I was doing a search on this subject and I came through a great sample code, which can explain how to do a lot of things and here is the link to that sample code:
http://developer.apple.com/iphone/library/samplecode/uicatalog/Introduction/Intro.html
I hope that this will help.

Possible to use iPhoneSimulators framework in a Cocoa App?

I am toying with the idea of creating a iPhone UI editor that isn't Interface Builder! Mostly to see if it is possible to do... I have been able to link to the UIKit.framework in a Cocoa app that I have created by dynamically loading it (via NSBundle functionality). I have been able to instantiate an UIView from there. Now the question is... how do I get to whatever the UIView renders?
I am trying to figure out how Apple implemented their Simulator since it seems likely that they are using the frameworks under the iPhoneSimulator.platform folder to do the rendering and then displaying that in a Cocoa window...
I am not sure how far I can go with this idea..but if anyone has any ideas how to direct the output of the UIVIew to a bitmap then I could take that and display in my Cocoa window...
Thanks,
Peter
You might try making an NSView subclass that hosts a UIWindow. In the NSView's drawRect:, apply any necessary transformations, then send drawRect: to the UIWindow.
Then, set your simulator NSWindow's content view to an instance of that subclass.