Showing posts with label StoryBoard. Show all posts
Showing posts with label StoryBoard. Show all posts
Saturday, March 17, 2018
HTML front end with back end with Objective-C
We are in the process of revamping all our iOS apps recently using: HTML+CSS+JavaScript to handle the front end and the back end is handled by Objective-C. The development became very interestingly for both UI designer and the programmer.
Before we took this approach, we were adding new functionality using Swift. After a few version upgrade on Swift/XCode, we found out that compilation error and warning will make us go mad. We don't think we can handle this and we don't like this to happen again and again. So, we decided to migrate all Swift codes that we have written back to Objective-C.
The next thing we are facing is the UI (user interface) and we are tiring in looking for solution on showing the popup and adjust the coordinate the popup appear in the correct position, etc. The storyboard file is particularly another bottleneck and wasted a lot of hours in "waiting for others to complete before they can start work".
With the new approach, the UI designer will work on the HTML+CSS. Once the layout has been confirmed by the team, the UI designer will continue to work on beautifying it and the Javascript & Objective-C programmer will start coding.
This approach reduce the development time as well as adding new features tremendously.
Time wasted in Swift version upgrade:
- New attribute
- Casting with ?, ?? or !....
- Casting between the data type: NSString, NSString?, NSString!....
Time wasted in implementing new idea using Storyboard:
- How to show a popup window.
- How to position the popup window correctly.
- How to partition a "view" into smaller view(s)/component(s) and then aggregate it to what we want.
- Screen flow/navigation.... try this API.. not this one, try another one... ah... obsolete API, look for new API... endless.. :(
With new approach:
- HTML+CSS - that's my what my UI designer good at.
- Javscript - that's what we are doing for web application since 2008.
- Objective-C - this is not the area that we are good at and we can't afford to spend too much time in researching for the correct code. But, we need is to store the data and load the data. Since we are good in SQL statement and we decided to store the data in SQLite.
Future upgrade for the app...?
- Adding new HTML elements.. small problem.
- Reposition the popup... small problem.
- Revamp the color theme... small problem.. just replace the color and background color in CSS.
- Adding new screen... just add a new HTML file.
- Adding new function... just add a new Javascript to handle and some backend code in Objective C.
Our objective is to minimize the upgrade time and cost. Another thing is that we don't need to use any big framework that is already doing this (you can Google search for it) because those framework upgrade might break and we need to spends many hours in chasing their tail.
We love programming but we don't like to chasing the tail become someone decided to make some API obsolete and replace it by some new API.
:)
Labels:
iOS,
iOS Browser,
Object-C,
StoryBoard,
UIWebView,
Web Browser
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:
Labels:
Cocoa,
iOS,
Object-C,
Screen Flow,
StoryBoard,
UITableView
UITableViewController settings
Declare a class that inherits from UITableViewCell and add a UILabel outlet. In CMyCell class, you may write some customized code. For example, when the view controller passing the data to the cell, the cell will display different controls based on the data.
Then, switch to the Storyboard, choose the"cell view" and set it's class name to "CMyCell".
Drag the label control to the "mainLabel" as shown below:
Then, switch to the Storyboard, choose the"cell view" and set it's class name to "CMyCell".
Drag the label control to the "mainLabel" as shown 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];
}
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];
}
Thursday, October 4, 2012
Why does prepareForSegue occur before didSelectRowAtIndexPath
The content was copied from:
http://stackoverflow.com/questions/10376967/in-ios-app-why-does-prepareforsegue-occur-before-didselectrowatindexpath
http://stackoverflow.com/questions/10376967/in-ios-app-why-does-prepareforsegue-occur-before-didselectrowatindexpath
Do you have your detail segue attached to the
table view cell? Instead, try dragging it between the two view
controllers (the one containing the table and the one where you want it
to go).
Then perform it manually when tableView:accessoryButtonTappedForRowWithIndexPath:.
Then perform it manually when tableView:accessoryButtonTappedForRowWithIndexPath:.
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
NSString *fullURL = self.url_txt.text;
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.browser_ctl loadRequest:requestObj];
}
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:
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:
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:
First, you need to create a new project in XCode and add a few view controllers as shown below:
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 10, 2012
Password field in iOS
Drag a Text Field on the screen, tick the "Secure" option. This will hide the character type by the user.
Note: please take note that the last character typed by the user will become hidden after a few seconds. That is the iOS behavior.
Note: please take note that the last character typed by the user will become hidden after a few seconds. That is the iOS behavior.
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.
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.
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.
Subscribe to:
Posts (Atom)













