Updates from July, 2012 Toggle Comment Threads | Keyboard Shortcuts

  • Jay Versluis 11:08 am on July 31, 2012 Permalink | Reply
    Tags: ,   

    Categories: iOS ( 222 )   

    How to pass an Index Path to another table 

    Say you have a central array somewhere and would like display this in more detail via two table view controllers. Instead of passing only the relevant information, you want to pass the entire index path from table1 to table2 and beyond.

    You can pass data in the prepareForSegue:sender method and let the Storyboard to the heavy lifting:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
        Table2 *table2 = segue.destinationViewController;
        table2.myIndexPath = [self.tableView indexPathForSelectedRow];
    }
    

    Here we instantiate a new Table2 object on which myIndexPath is a property. Then we set it to our own table’s selected indexPath. In Table2 we can then pick it up and read out the array’s property.

    Note that the didSelectRowAtIndexPath method of the table view can be completely empty for the data to be passed on. In fact, should you try an pass data in this method it won’t be available until the table is drawn.





     
  • Jay Versluis 9:43 am on July 27, 2012 Permalink | Reply
    Tags:   

    Categories: iOS ( 222 )   

    How to create a custom button 

    We can do this by setting properties of the UIButton for the states “normal” and “highlighted”. First we create pointers to the images, then we tell the button to use said images for each state:

    If the button has transparency enabled use the “custom” setting in your Storyboard.
    If the button should have a dynamic width to accommodate a changing text label you can use the following values:

    UIImage *normal = [[UIImage imageNamed:@"greyoffbutton.png"]stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
    




     
  • Jay Versluis 2:37 am on July 24, 2012 Permalink | Reply
    Tags: UIActivityIndicator,   

    Categories: iOS ( 222 )   

    How to add the “spinning wheel” Activity Indicator to a web view 

    It’s always good to have something happening while you’re loading a UIWebView. You can use the UIActivityIndicator for this. It’s basically an animated GIF file that you can connect to your code like many other elements. To make it work we need to conform to the UIWebViewDelegate protocol and then query our web view to see if he’s finished loading.

    Here’s how we do that:

    • add the protocol to your header file
    • make sure you drag from your Web View to your View Controller’s delegate (control drag to the orange oval in your storyboard, at the bottom of your view controller)
    • add the method webViewDidFinishLoad:(UIWebView *)myWebView
    • in it call the stopAnimating method for your spinning wheel.

    In the storyboard make sure that you set the behaviour of the Activity Indicator to “animating” and “hides when stopped”.

    Here are my files:

    You can create the same effect in the status bar of your application. Click here for details.





     
  • Jay Versluis 1:00 pm on July 18, 2012 Permalink | Reply
    Tags: , NSMutableArray   

    Categories: iOS ( 222 )   

    How to convert an NSArray into an NSMutableArray 

    There’s a handy function called arrayWithArray that we can use:

    NSMutableArray *myNewArray = [[NSMutableArray alloc]init];
    myNewArray = [NSMutableArray arrayWithArray:myOldArray];
    

    Likewise we can convert a mutable array into a standard one:

    NSArray *myStandardArray = [[NSArray alloc]init];
    myStandardArray = [NSArray arrayWithArray:myMutableArray];
    




     
  • Jay Versluis 6:53 am on July 18, 2012 Permalink | Reply
    Tags: , UILabel   

    Categories: iOS ( 222 )   

    How to change the text on a Button 

    You can set the title of a button depending on its control state. An unselected untoched button has a UIControlStateNormal, but Xcode will show you all the other options you have at your fingertips.

    To access this property you need to create an IBOutlet on the button. If you also want the button to trigger an action you also have to define an IBAction.

    [self.myButtonLabel setTitle:@"Your text here" forState:UIControlStateNormal];
    




     
  • Jay Versluis 4:54 pm on July 13, 2012 Permalink | Reply
    Tags:   

    Categories: iOS ( 222 )   

    How to convert an integer into a string (text object) 

    I keep forgetting how to do this so here it is: if you have an integer and you want to print it out, say in a UILabel you can use the initWithFormat method of NSString like so:

    NSString *myNumber;
    myNumber = [[NSString alloc] initWithFormat:@"%d", myInteger];
    self.myLabel.text = myNumber;
    

    The secret here is the @”%d” which is called a String Format Specifier (search for it in the Developer Docs).





     
  • Jay Versluis 4:32 pm on July 13, 2012 Permalink | Reply
    Tags: Push, , , UITabBarController,   

    Categories: iOS ( 222 )   

    How to share data between Navigation Controllers 

    The Root Navigation Controller can serve as a data model. Each View Controller connected to the Navigation Controller via push segue can access its properties like so:

    ((MyNavController *)self.parentViewController).mySourceProperty
    

    Here’s an example. MyNavController is the class for the Navigation Controller. This snipped is called from any View Controller in sequence and assumes we have an integer myNumber which is increased by one:

    ((MyNavController *)self.parentViewController).myNumber++;
    

    The same principle works for Tab Bar Controllers too.





     
  • Jay Versluis 10:11 am on July 9, 2012 Permalink | Reply
    Tags: Modal, ,   

    Categories: iOS ( 222 )   

    How to trigger a Modal Segue 

    Once you’ve connected two View Controllers via a Segue in the storyboard you need to give it an identifier so we can call it in code like so:

    [self performSegueWithIdentifier:@"showDetail" sender:self];
    

    Dismiss it via an action like this:

    [self dismissViewControllerAnimated:YES completion:nil];
    




     
  • Jay Versluis 2:13 pm on July 7, 2012 Permalink | Reply
    Tags: ,   

    Categories: iOS ( 222 )   

    How to load a URL into a web view 

    Everything has to be that bit more complicated with iOS doesn’t it?





     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel