InitWithCoder: and serialization vs Interface Builder

Ok, i am trying to make a game that:
1. loads a view (stored in a .xib file)
2. places the objects in that view in the same position they were before ("loadgame") if it isn`t the first time the application was launched.
My question is: how can i use IB and initWithCoder: to place my objects in the place they were supposed to be? I know that initWithCoder: is called when an object is loaded from a .xib file, but that will only load the objects default atributes, right? If I then encodeWithCoder: an object how can i later re-create the object with the new atributes?
Sorry about my english =/
I really could use some help with this.

I would suggest to handle that later, after the view is loaded from the nib-file.
There's a method called "viewDidLoad" which is called right after the view is set. This would be a good place to rearrange the object's positions.

Similar Messages

  • IPhone Interface Builder Tutorials???

    New to Objective-C, X-code, etc. and now that Interface Builder came out for the iPhone SDK, I can't seem to find any information at all on how to use it (it does not seem to integrate with X-code as I have found in non-iPhone development work with X-code and IB.
    Could someone please suggest or direct me to websites, videos, or books that would help a complete novice use this tool? Thanks.

    Thanks for the reference.
    I have to say the process using IB is very intuitive - NOT.
    I've been reading an older O'Reilly Cocoa book and it makes at least some sense and seems to be integrated with X-code for Mac development without tweaking the default code. I see a steep learning curve ahead as heavy use of secret right-clicks and unintuitive dragging are usually to be frowned upon except for folks who have already climbed that mountain (if you even know why you're doing it .
    I hope more is coming from Apple.

  • File's Owner does not show methods in Interface Builder 3.2.6 but the class is set correctly and the nib on the lower left is green

    Hi, I'm trying to make my first IPhone app. After having problems with interface builder the first time I coppied the code directly from a tutorial in case I made any mistakes. I saved the program, and re-opened the .xib file. Right clicking  File's Owner does not show a list of methods. I've been looking around for solutions for this but have not gotten anything to work. I tried deleting the default .xib and creating a new one through file-> new file. This did not help. I did notice that File's owner was showing up as a light blue cube apposed to a yellow one now and found that a bit odd but otherwise nothing changed. I opened the library menu and selected helloWorldiPhoneViewController so it would show up in the view port. I set the class field of File's Owner to hellowWorldiPhoneViewController. File's Owner still does not show methods when right clicked or when a line is dragged over a button. I read somewhere that the color of nib on the lower left of the viewport may indicate a problem, but it is green not indicating any issue. Every solution I found for someone else seems nto to work for me and I don't know how to continue.
    here is the .h file just in case:
    //  HelloWorldViewController.h
    //  HelloWorld
    //  Created by Paul Peelen on 2011-03-14.
    //  Copyright 2011 9697271014. All rights reserved.
    #import <UIKit/UIKit.h>
    @interface HelloWorldViewController : UIViewController {
            UILabel *textLabel;
    @property (nonatomic, retain) IBOutlet UILabel *textLabel;
    - (IBAction)changeTheTextOfTheLabel;
    @end
    I'm trying to connect changeTheTextOfTheLabel to a button and textLabel to a label

    You need a parameter for an interface builder method. The type should be id and the name is typically "sender". It would look like this:
    - (IBAction)changeTheTextOfTheLabel: (id) sender;
    Be careful about those tutorials. Many are ancient and do not correspond to current Xcode behaviour.

  • Using interface builder to create a table view and add a cell

    So I am using interface builder to make a table view. Should be easy. I drag a table view controller to my view, then it seems I should be able to drag a table view cell to the table view but it won't let me drop it down. If I do it in the documents window it just replaces the table view with a cell. Seems like this shouldn't be hard, but it's one of those things that should take 2 seconds but I have been messing with it for hours. It seems like most of the examples I have looked at in the same code don't use iB so I haven't found a good reference. If somebody can point me in the write direction let me know.

    I struggled a bit too. Here's what I did on my recently completed app. I used IB to create the basic view and add the table. That's it. Then ensure your UIViewController based class implements the UITableViewDelegate and UITableViewDataSource protocols. Your cells will come from those methods, not anything you do in IB.
    If you're creating a set of screens that just have tables that allow you to navigate up and down through the data then IB isn't worth using at all.
    Just have your views extends UITableViewController and follow some of the supplied table based example apps.
    I rewrote my first app 3 times as I slowly figured all of this out.
    Hope that helps.

  • I am new to xCode and SDK Disks. My Interface Builder will not work and 'quit's unexpecteldy'. What can I do? I really want to create an applicaiton. Thanks

    Hi, I am a new user to xCode and just recently downloaded a SDK Disk image and also an older version of xCode from the Apple Developer site. I opened the 'Interface Builder' for the first time and it worked. Next, when I tried to open it again (with and without the xCode 'Mainmenu.xib' attachment file from xCode) it kept showing the message "it quit unexpectedly".
    I need to create an application for a project I am working on. If anyone who can resolve my problem of why the Interface Builder is not working, that will be great.
    If you need additional details (like which versions etc.) please ask, for I am desperate to find an adequate solution to this problem.
    Thanks.

    If you need additional details (like which versions etc.) please ask, for I am desperate to find an adequate solution to this problem.
    Without intending any disrespect, if you had suspected these would be questions and if you're in a hurry for an answer, then why did you exclude the information?  And yes, knowing the Mac OS X version (preferably Mac OS X 10.5.8 or 10.6.7) , as well as the Xcode version might shed some light on this.  Might.  And I'll presume there's a specific reason you downloaded what I will assume is an Xcode3 version.
    Was this an existing Xcode project, or did you start with a new project here?  If it's an existing project, it could well have a corruption or an incompatibility.
    Initially, I'd probably start with a new project, and load in newly-copied source files.  On the off chance the project is corrupted.
    Failing that, I'd deinstall Xcode using the documented procedures, and would then reload it.  If there was an old version of Xcode around on the system, sometimes wonky stuff can happen with an installation.
    And FWIW, the Apple Developer Forums and the Apple mailing lists tend to see far more developer-related traffic than do these particular forums.  (There's an Xcode users' mailing list around which sees regular traffic, too.)

  • [iphone] sub ViewController in UITableView and Interface Builder

    Hello,
    I created a UITableView-based application and now I would like to display a simple view after selecting a cell (drilldown feature).
    I create a xib file in Interface Builder by following the guide "Configuring the Views for Additional Navigation Levels" in http://tinyurl.com/6cdh2k and I instantiate my controller using the method describe here http://tinyurl.com/5ft7ug
    in my method didSelectRowAtIndexPath :
    ViewStoryController *detailStoryController = [[ViewStoryController alloc] initWithNibName:@"StoryDetails" bundle:nil];
    detailStoryController.story = story;
    [[self navigationController] pushViewController:detailStoryController animated:YES];
    But my screen is blank but for the navigation bar. I think it must something about init/load methods etc ... I missed something ?
    Matthieu

    Hello,
    I created a UITableView-based application and now I would like to display a simple view after selecting a cell (drilldown feature).
    I create a xib file in Interface Builder by following the guide "Configuring the Views for Additional Navigation Levels" in http://tinyurl.com/6cdh2k and I instantiate my controller using the method describe here http://tinyurl.com/5ft7ug
    in my method didSelectRowAtIndexPath :
    ViewStoryController *detailStoryController = [[ViewStoryController alloc] initWithNibName:@"StoryDetails" bundle:nil];
    detailStoryController.story = story;
    [[self navigationController] pushViewController:detailStoryController animated:YES];
    But my screen is blank but for the navigation bar. I think it must something about init/load methods etc ... I missed something ?
    Matthieu

  • Interface Builder and subclassing

    Is it possible for me to have the outlet in Interface Builder pointing to a superclass... then in the code using that interface to point to a subclass?
    So for example, suppose I'm setting up an interface in Interface Builder with a HumanView (let's say this is a subclass of UIView)... suppose this is like a character in an MMORPG... and you're customizing your chaacter...
    and correspondingly in my code I have:
    IBOutlet HumanView *character;
    But I'm uncertain whether this view will be a female or male character... In my code I have two subclass of HumanView... FemaleView and MaleView... each with its own unique instance variables and methods...
    Is it possible for me to decide in the program to have make "character" a FemaleView or MaleView?
    Thanks.
    Message was edited by: iphonemediaman

    Not a problem. I did realize I should add one minor clarification.
    1) You can cast a quadralateral to a square in one instance. When you know that actual object (the structure in memory) is a square.
    So, to be complete, you can safely cast a the square to a quadralateral all day long -- you know that a square is always a quadralateral. But if you are going to cast the quadralateral to a square, you should make sure you actually have a square object. The compiler will let you do it (might show a warning), but you could end up trying to reference pieces of a square that may not actually be part of the actual object. aka (in pseudo code):
    // no issues with these two alloc/inits
    Quad *foo = (Quad *)[[Square alloc] init];
    Quad *bar = (Quad *)[[Rectangle alloc] init];
    // both would return 4
    [foo numSides];
    [bar numSides];
    // if setSideLength is only a method on a Square, then
    // first line works fine
    [(Square*)foo setSideLength:20.0];
    // this line, however, will likely give a compiler warning and then
    // an EXC_BAD* error during runtime -- bar is not actually a square
    // in memory, despite what you are telling the compiler
    [(Square*)bar setSideLength:20.0];
    I hope I didn't conuse the issue -- but wanted to clarify.
    Cheers,
    George

  • Interface builder and xcode

    ok, im a complete newbie to xcode and interface builder,
    so, wen i try to make a connection for a new outlet and click 'files owner', all it shows is 'delegate', instead of files tat i hav in my resource folder, or the files im supposed to hav, anyone could help me on this? it would be appreciated greatly, thx

    Hello joshup7 & welcome to the forums...
    Generally speaking, you first need to properly specify items in your templates/code (*.m & *.h files) in Xcode and then they will show up when making connections in IB. Who/what/where/why depends on your specific code, naming conventions, etc.
    See this page from Apple:
    http://developer.apple.com/iphone/library/documentation/DeveloperTools/Conceptua l/IB_UserGuide/Introduction/Introduction.html
    And this sample/tutorial that should cover the basics:
    http://www.iphonesdkarticles.com/2008/07/first-iphone-application.html
    ...see the section on 'Connecting Instance Variables'.

  • Inspector and Library Window are always on top in Interface Builder

    Hi,
    Inspector and Library Window are always on top in Interface Builder. I use a small 13" macbook screen most of the time and I don't have a lot of room. Just wondering if I can disable this so I can have my work area hover over the library and inspector when I'm not using them.
    Thanks

    I still have not been able to figure this out. The best I could do is resize each of these windows to really small and maximize them when using them. But they're still always on top and this is really annoying.

  • What to do if you use a segmented control in interface builder and it doesn't work ?

    What to do if you use a segmented control in interface builder and it doesn't work ?

    The first thing to do would probably be to update your profile and/or signature so people will know what OS, language, and development system you are using, then perhaps include some additional information such as what "it doesn't work" means, and possibly a few other things like some error logs, what you have done so far, maybe a code snippet or two, etc.

  • UITableViewCell and the Interface Builder

    I'm trying to use the Interface Builder to create a UITableViewCell but am having problems.
    I can create the UITableViewClass in my .xib file, connect the reference outlet and reuseIdentifier using the inspector. The problems occurs when I try and render the cell with this method...
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    Since the interface builder creates the TableViewCell automatically, I should be able to call...
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"priceCell"] autorelease];
    ..from inside the tableView:cellForRowAtIndexPath method and get that cell instance. But none of changes (Color, accessory view, etc...) I made to the table view come through.
    Has anyone got UITableViewCells created in the interface builder to work?

    Just an update to inform people of some of my findings.
    I had originally, before gkstuart's post, had added a UITableViewCell instance as a child of my view in IB. I then tried to use the cell via an IBOutlet in the UITableView in my view. This is when I was getting a completely blank screen when running my application. I then adopted gkstuart's idea and created a cell factory class, but without thinking, I used the same cell instance on each call to my 'newCell' method. Once I updated the 'newCell' method to load the nib file on each call to 'newCell' everything seems to work fine. As a note, the nib file loaded by 'newCell' is a simple nib file containing only my custom cell definition. It does not contain any views. Gkstuart's method of loading custom cells is unfortunate, because you can't seem to use the reusable cell theory when working with cells defined in IB. This is obviously something that needs work on Apple's side.
    As a test, I removed my custom cell definition from my original view nib. I then added a new top level instance of UITableViewCell, by dragging the UITableViewCell item to the window with the File Owner icon. After updating the custom cell definition with the appropriate class and outlets, I tried my original method again. I no longer get a completely blank screen, but it still doesn't work right. I now get a single cell in my table view, which happens to be the last cell in the list. When looking at it with the debugger, dequeueReusableCell never returns my cell instance so I am reusing and returning the same cell for each call to 'cellAtIndexPath'. I tried to manually call the cells 'prepareForReuse' method but this didn't seem to have any affect.
    So at this point, I am going to continue with the cell factory methodology until Apple either fixes the current problem or informs people on the proper way to use IB with custom UITableViewCell's.
    As a side note, I am going to start blogging about my experiences with the iPhone SDK over at iphonesdktrialsandtribulations.blogger.com.

  • Install iphone simulator and interface builder

    I have purchase new mac book pro . I got xcode in media but how can i install iphone simulator and interface builder..
    some body can give me link for that.....
    thanks in advance..

    Sorry, false alarm...10.5.3 failed to install properly prior to updating to beta 6 and as a result the SDK itself didn't install.

  • Xcode and Interface Builder

    Hello,
    I want to make a thing in Interface Builder so that when I click on the About "My Application" menu in the Menu Bar at the top a new window comes up.
    What I did, was made a new window (HUB) then, deselected Visible at Launch. I did all the linking stuff with applescript and when I tested (Apple - R) it showed up! Any idea why and how to fix this problem?
    Thanks!
    P.S. My app is an AppleScript app
    And also, if you can, how do you "export" your finished apps from Xcode?

    bubblejelly wrote:
    I want to make a thing in Interface Builder so that when I click on the About "My Application" menu in the Menu Bar at the top a new window comes up.
    Umm, OK. But you should get an "About" window by default without having to do anything. Are you saying you want another window too, or a different window than the default one?
    What I did, was made a new window (HUB) then, deselected Visible at Launch. I did all the linking stuff with applescript and when I tested (Apple - R) it showed up! Any idea why and how to fix this problem?
    HUB? Not sure what that means.
    Did you do the Apple-R in Xcode or in Interface Builder? "Test Interface" (or Apple-R) in Interface Builder is not the same as "Build and Run" (Apple-R) in Xcode. In IB if your "not visible" window is open when you do the Apple-R then it will also be open when the interface test is in progress. None of your AppleScript code gets executed when you're testing in IB.
    If you were doing the Apple-R in Xcode then I don't know. Post some of your AppleScript code.
    Steve

  • Comparable and Serializable interfaces

    Hi All,
    I have developed a program in java which implements Comparable and Serializable Interfaces. After, I decided to run the program in J2ME. But later on, I found that MIDP doesn't implement these interfaces.
    Some one can help me how to implement my own interfaces.
    Thank you

    Hi Supareno
    I need urgently your help.
    I developed Java program which works as predicitive text system for my mother tongue.I would like to move from Java to J2ME. But until now I have problems. please can u help me. the following code run in command line.
    I tried to develop my own interfaces as you told me but it doesn't work.
    Help me also for reading and writing text files.
    Thank you
    import java.util.*;
    import java.io.*;
    import java.util.Vector;
    import java.util.Enumeration;
    public class PredText {
    private Vector dict;
    public static final String dictionaryFile = "C:/java/words.txt";
    // convert a string to the corresponding signature
    public static String toNumeric (String word) {
    String lowerWord = word.toLowerCase();
    StringBuffer result = new StringBuffer("");
    for (int i = 0; i < lowerWord.length(); i++) {
    char c = lowerWord.charAt(i);
    if ("abc".indexOf(c) > -1) result.append("2");
    else if ("def".indexOf(c) > -1) result.append("3");
    else if ("ghi".indexOf(c) > -1) result.append("4");
    else if ("jkl".indexOf(c) > -1) result.append("5");
    else if ("mno".indexOf(c) > -1) result.append("6");
    else if ("pqrs".indexOf(c) > -1) result.append("7");
    else if ("tuv".indexOf(c) > -1) result.append("8");
    else if ("wxyz".indexOf(c) > -1) result.append("9");
    else if (" ".indexOf(c) > -1) result.append("9");
    else result.append("?");
    return result.toString();
    // find all the words corresponding to a signature
    public Vector findMatches(String sig) {
    WordSig ws = new WordSig(sig, "");
    WordSig newws;
    Vector results = new Vector();
    int index;
    index = Collections.binarySearch(dict, ws);
    if (index < 0){
    // no matches! :(
    // try to get the string that starts with a substring like ours.
    index=-1-index;
    if (((WordSig)dict.get(index)).getSig().startsWith(sig)) {
    // no word found. we return those starting with the
    // same signature
    newws = (WordSig) dict.get(index);
    results.addElement(newws.getWord().substring(0,sig.length()));
    return results;
    } else{
    //no match
    return results;
    } else {
    // go back to the first match
    while(((WordSig)dict.get(index)).getSig().equals(sig) && index>0)
    index--;
    if (index != 0)
    index++;
    while ((newws = (WordSig) dict.get(index)).equals(ws)){
    results.addElement( newws.getWord() );
    index++;
    return results;
    // intialises the dictionary
    public PredText () {
         String word;
    String sig;
    Vector dict = null;
    // first try to load dict.dat
    try {
    System.out.print("Trying to load dict.dat...");
    FileInputStream fileStream = new FileInputStream("C:/java/dict.dat");
    ObjectInputStream objectStream = new ObjectInputStream(fileStream);
    dict = (Vector) objectStream.readObject();
    fileStream.close();
    System.out.println(" done.");
    }catch (ClassNotFoundException classNotFoundException) {
         System.out.println("Unable to create an object");     
    catch (IOException e) {
    // exception: create the dictionary
    System.out.println("Error. I'm going to recreate the dictionary file");
    try {
    dict = createDict();
    catch (IOException ioe) {
    System.err.println("Error while creating dictionary file. Exiting." + e);
    System.exit(1);
    this.dict = dict;
    // create the dictionary serialised file
    public Vector createDict () throws IOException {
    String word;
    Vector dict = new Vector();
    //open the dictionary file
    System.out.print("Reading the dictionary... ");
    BufferedReader dictFile = new BufferedReader(
    new FileReader(dictionaryFile));
    //insert each word into the data structure
    while ((word = dictFile.readLine()) != null) {
    word = word.toLowerCase();
    dict.addElement(new WordSig(toNumeric(word), word));
    // List list = dict.subList(0, dict.size());
    List list = dict.subList(0, dict.size());
    Collections.sort(list);
    System.out.println("done.");
    System.out.print("Writing the dictionary... ");
    FileOutputStream fileStream = new FileOutputStream("C:/java/dict.dat");
    ObjectOutputStream objectStream = new ObjectOutputStream(fileStream);
    objectStream.writeObject(dict);
    objectStream.flush();
    fileStream.close();
    System.out.println("done.");
    return dict;
    public static void main (String args[]) {
         PredText pt = new PredText();
    if (args.length == 0) {
    // no arguments, find the largest clash
         Vector result;
         Enumeration e = pt.dict.elements();
    String currentSig = "";
    String prevSig = "";
    int clash = 0;
    int maxClash = 0;
    String clashSig = "";
    while (e.hasMoreElements()) {
    WordSig ws = (WordSig) e.nextElement();
    currentSig = ws.getSig();
    if (currentSig.equals(prevSig)) {
    // another word with the same signature
    clash ++;
    } else {
    // new signature: check if the previous one led
    // to a maximal clash
    if (clash > maxClash) {
    clashSig = prevSig;
    maxClash = clash;
    clash = 1;
    prevSig = currentSig;
    result = pt.findMatches(clashSig);
    System.out.println("The signature leading to most clashes is "
    + clashSig + " with " + result.size() +
    " number of clashes");
    for (int j = 0; j < result.size(); j++) {
    System.out.println((String)result.get(j));
    } else if ("0123456789".indexOf(args[0].charAt(0)) > -1){
    // numeric input: find the matches for the argument
    Vector result;
    result = pt.findMatches(args[0]);
    for (int j = 0; j < result.size(); j++) {
    System.out.println((String)result.get(j));
    } else {
    // convert each word to the corresponding signature
    for (int i = 0; i < args.length; i++) {
    System.out.print(toNumeric(args) + " ");
    class WordSig implements Comparable, Serializable {
    String word;
    String sig;
    public WordSig (String sig, String word) {
    this.sig = sig;
    this.word = word;
    public String getSig () {
    return this.sig;
    public String getWord() {
    return this.word;
    public int compareTo (Object ws) {
    return sig.compareTo(((WordSig) ws).getSig());
    public boolean equals (Object ws) {
    return sig.equals(((WordSig) ws).getSig());
    public String toString () {
    return sig + ", " + word;

  • Comparable and Serializable Interfaces in MIDP

    Hi All,
    I have developed a program in java which implements Comparable and Serializable Interfaces. After, I decided to run the program in J2ME. But later on, I found that MIDP doesn't implement these interfaces.
    Some one can help me how to implement my own interfaces.
    Thank you

    Thank you for replying to me.
    My problem is to compare to objects in MIDP.
    You know that in java is possible to implements directly the Comparable interface but in MIDP is not the same. So I think it requires to create your own. Is that my question.
    I need some to help me. just to avoid the implentation of comparable interface from the java lang package.
    Thank u.

Maybe you are looking for

  • Officejet 8620 don't print on Windows 8.1

    Hi, I purchased a Officejet 8620 to replace an Officejet 8600 PRO irreparably damaged by lightning. The printer is connected via wired ethernet. I installed the software on the CD on a HP laptop with Windows 7 Ultimate and the printer, scanner and fa

  • Can I upgrade my version of Mavericks without being forced into Yosemite

    Can I upgrade my version of Mavericks without being forced into Yosemite ? Apparently, Yosemite breaks iMovie HD (a.k.a. iMovie 06).   I am considering a new Macintosh with 10.9.1  I would like to go to 10.9.5. Thanks

  • Photoshop 7 is dead - with Leopard

    Well Leopard killed Photoshop 7 on my MacBook, don't know about my G5 yet.

  • Moving from Dell PC to Intel Mac

    I have a Dell PC and an intel mac. Both have firewire, USB and ethrnet ports. I would like to share files directly between the two machines, does anyone have any advice on the simplest method to achieve a connection. I saw in a previous post how to d

  • Logic board or graphic/video card failure?

    I have an iMac Core 2 Duo (Late 2006) 2.16 GHz, max RAM. I have been getting kernel panics and/or the screen with gray overlay and the multilingual instructions to re-start. I don't know whether I have impending logic board, video/graphic card failur