Showing posts with label Screen Flow. Show all posts
Showing posts with label Screen Flow. Show all posts

Wednesday, June 12, 2013

Section in UITableViewController

In table view, you may create sections to group the cells. To do this, just follow the settings below:


Monday, October 22, 2012

Showing drop down list

In iOS, there is not "combo box" or "drop down list" control as compare to Windows programming. But, there is a way to achieve this.

Below is the screen snapshot that tells you that yes, there is a way to show the drop down list when the user clicks on the "Choose.." button.



First, you have to add a table view controller to the Storyboard and set its' Identifier to "testTableView".


After that (in this new table view controller), you have to populate the data through the numberOfRowsInSection and cellForRowAtIndexPath method. Nothing special here.

In the didSelectRowAtIndexPath, you have to pass the user selection back to the "main view". "setSelection" is a method in the main view controller (the codes will be shown later).

- (void)tableView:(UITableView *)tableView
    didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString* s = [self.data objectAtIndex:indexPath.row];
    [self.main_view setSelection:s];
}

In the viewDidLoad, you have to write some code to control the popover size.

    CGRect rect = [self.tableView rectForSection:0];
    self.contentSizeForViewInPopover = CGSizeMake(200,
                                                  rect.size.height + 20);

In the .h class of the main view, you have to add the UIPopoverControllerDelegate protocol and also a popover controller variable.

   @interface CViewController : UIViewController<UIPopoverControllerDelegate>
   @property(strong)UIPopoverController* popover_controller;

In the .m file of the main view, you have to add two method for the above protocol.

   - (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController{
        return YES;
   }

   - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController{
      //do cleanup here, if any. 
   }

Through the StoryBoard, select the main view and you have to add the button reference and handle the TouchDown (like click event in the Windows programming). The codes are shown as below:

- (IBAction)choose_btn_onclick:(id)sender {
    if(self.popover_controller == nil)
    {
        CTestViewController* vc =[self.storyboard instantiateViewControllerWithIdentifier:@"testTableView"];
        vc.main_view = self;
       
        UIPopoverController* popover= [[UIPopoverController alloc] initWithContentViewController:vc];
        popover.delegate = self;  
        self.popover_controller = popover;
    }
   
    CGRect popover_rect = [self.view convertRect:[choose_btn frame]
                                        fromView:[choose_btn superview]];

    [self.popover_controller presentPopoverFromRect:popover_rect
                                             inView:self.view
                           permittedArrowDirections:UIPopoverArrowDirectionAny
                                           animated:YES];
}

The popover controller will pass the user selection through this method:

-(void)setSelection:(NSString*)s
{
    self.choose_btn.titleLabel.text = s;
    [self.popover_controller dismissPopoverAnimated:YES];
}

Tuesday, October 16, 2012

Updating UI by the background thread

As simple as this:

 // Add to top of file
 #import <dispatch/dispatch.h>
 
 if ([NSThread isMainThread])
 {
  [self MyMethodName];
 }
 else
 {
  dispatch_sync(dispatch_get_main_queue(), ^{
   //Update UI in UI thread here
   [self MyMethodName];
  });
 }
 
Reference:
http://www.ios-developer.net/iphone-ipad-programmer/development/threads/updating-ui-controls-on-background-threads
http://www.raywenderlich.com/4295/multithreading-and-grand-central-dispatch-on-ios-for-beginners-tutorial

Tuesday, October 9, 2012

Showing alert on the screen

In .Net, we are using MessageBox to show the alert on the screen. In iOS, we are going to use UIAlertView.

Below is the sample code copy

        UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"Helo world"
            message:@"This is the popup message." 
            delegate:self cancelButtonTitle:@"OK"
            otherButtonTitles:@"Clear", nil]];
        [av show];

Monday, September 24, 2012

Develop a simple mobile web app

The simplest way to develop a mobile web app is to show a UIWebView in the iOS screen. The app itself will remain it's process in the web server. In short, you can't avoid developing the application functionality. Instead, you may roll out the implementation faster.

By using this design, you may hardcode the web server URL into the mobile web app so that your user does not have to remember what is your URL. The other advantage is that it is able to handle the Push Notification from the server.

The following article provides all the necessary sample codes on how to implement it.

http://developer.apple.com/library/ios/#DOCUMENTATION/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/DisplayWebContent/DisplayWebContent.html

Things that you may try out
  • Drag a text field, a button and a WebView to the iOS screen.
  • The UIWebView is referencing by "browser_ctl".
  • The button is referencing by "go_btn".
  • The text field is referencing by "url_txt".
  • Finally, link the button click event to the following method:
- (IBAction)ongo_click:(id)sender {
    NSString *fullURL = self.url_txt.text;
    NSURL *url = [NSURL URLWithString:fullURL];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [self.browser_ctl loadRequest:requestObj];
}

Wednesday, September 12, 2012

StoryBoard and screen flow

At first, I was struggling with StoryBoard and wonder how to jump from one screen to another. After some research in the web, I found out that it is quite straight forward. But, you might be very confuse if you were came from Microsoft .Net which has different way to handle the screen flow. Let's try it out.

First, you need to create a new project in XCode and add a few view controllers as shown below:

Stroyboard


Then, design the main view as shown below. Two buttons and one segment control.



Below is the code that handle the on click event for a button which will navigate to another screen. The "auto flow over" button does not handle the click event.

- (IBAction)manual_push_onclick:(id)sender {
  
    NSInteger i = [self.view_selection selectedSegmentIndex];
    if (i == 0)
    {  //show view 1
        [self performSegueWithIdentifier:@"manualSegue" sender:self];
    }
    else if (i == 1) {
        // show  view 2
        [self performSegueWithIdentifier:@"manualSegue2" sender:self];
    }
    else if (i == 2)
    {
        // jump 1 level down (in segue) to another view.
        // goto 'View Controller' in storyBoard -> then set the 'Identifier'.
        CAnotherViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:@"anotherSegueViewId"];
        [self.navigationController pushViewController:vc animated:NO];
       
     }
    else
    {
        // goto 'View Controller' in storyBoard -> then set the 'Identifier'.
        // this view does not have any link with the main view controller.
        CFloatingViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:@"floatingViewId"];
        [self.navigationController presentModalViewController:vc animated:NO];
    }
}

31-May-2013
If you are wondering where to set the "anotherSegueViewId", attached with the screen snapshot. You need to open the storyboard and then select your view controller. Then, goto "Custom Class" and look for "Identity" section. Key in the storyboard ID.

To set the segue ID:


Monday, September 3, 2012

Designing the screen flow in iOS 5

After you have created the project which relies on the StoryBoard, you will have something looks like below.

To design the screen flow, first, you need to have a Tab Bar Controller. Then, you need two Navigation Controller-s which links to the first screen. After that, you may link it with details or table view controller.

To create the "link" between the controller, click on the Tab Bar Controller. Hold down Control key and drag your pointer to the Navigation Controller. Then, choose Relationship segue.


Friday, August 31, 2012

Set the default view/screen

When you are learning how to use the storyboard, you might accidentally deleted the main screen and ended up with a black screen appears in the simulator.

This is the steps that you can set the default main screen through Storyboard:


Keywords:
Change default view, change default screen, set main view, set main screen.