When you a shared library project in a workspace and there are category functions, the compilation will fail. To overcome this problem, you need to add "-ObjC" in "Other Linker Flags" as shown below:
Tuesday, October 30, 2012
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];
}
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
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]; |
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];
}
Monday, September 17, 2012
How to install the certifcates?
To distribute iOS app, you need all the necessary certificates generated by the iOS Provisional Portal. You will have a login ID and password after you have registered successfully with Apple.
To start the distribution or testing the app in any iOS devices, you need this:
The easiest way to generate the provisioning certificate is through your xCode 4.2 IDE. Run xCode and open any project. Click on the "Organizer" button located at the top right corner and you will get the following screen. Right click on Developer Profile and follow the options as shown below.
In the iOS Provision Portal, ensure that you have created the Development certificate and also the Distribution under Certificates section.
For the App IDs, it supports wildcard characters. So, it's upto you whether you want to create a new App ID or continue with the one that was generated by the xCode.
In the Provisioning section, you will see Development and Distribution as well. For the Development provisioning, the xCode will handle it. For the Distribution provisioning, you will have to generate it manually (after you have visited Certificates \ Distribution option as highlighted in the above).
Another thing is to import the certificates that you have downloaded from the portal (in case you want to create the certificate with your preferred name). Below is the steps to call out the Keychain program to install the certificates into your computer:
This is the Keychain program:
If you double click the certificate in the Finder, you will receive a warning because those certificate requires admin permission to get install. The proper way to do this is run the Keychain program, select File \ Import Items. Then, choose the certificate that you want to import. You need to key in your user name and password so that it can be installed.
Please take note that once you have installed the certificate manually, the xCode will pick it up automatically (but, you might have to refresh the list by selecting different node).
As for the "xxx.mobileprovision" certificate, you may double click on it and it will get install into xCode. Since there is no changes in the system, there will be no prompt for the admin password.
To start the distribution or testing the app in any iOS devices, you need this:
- provisioning certificate - this can be generated automatically by xCode.
- app ID - this can be generated automatically by xCode.
- distribution certificate - you need to manually do it.
In the iOS Provision Portal, ensure that you have created the Development certificate and also the Distribution under Certificates section.
For the App IDs, it supports wildcard characters. So, it's upto you whether you want to create a new App ID or continue with the one that was generated by the xCode.
In the Provisioning section, you will see Development and Distribution as well. For the Development provisioning, the xCode will handle it. For the Distribution provisioning, you will have to generate it manually (after you have visited Certificates \ Distribution option as highlighted in the above).
Another thing is to import the certificates that you have downloaded from the portal (in case you want to create the certificate with your preferred name). Below is the steps to call out the Keychain program to install the certificates into your computer:
This is the Keychain program:
If you double click the certificate in the Finder, you will receive a warning because those certificate requires admin permission to get install. The proper way to do this is run the Keychain program, select File \ Import Items. Then, choose the certificate that you want to import. You need to key in your user name and password so that it can be installed.
Please take note that once you have installed the certificate manually, the xCode will pick it up automatically (but, you might have to refresh the list by selecting different node).
As for the "xxx.mobileprovision" certificate, you may double click on it and it will get install into xCode. Since there is no changes in the system, there will be no prompt for the admin password.
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.
Thursday, September 6, 2012
How to load an image from resource file
It is very simple and straight forward to do in iOS:
UIImage *overlayImage = [UIImage imageNamed:@"bookmark.png"];
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.
Tuesday, August 28, 2012
Recording with QuickTime
You can record almost anything with your MacBook. Run QuickTime Player.
Then, choose File and select the options that you want. It's powerful and fun.
Then, choose File and select the options that you want. It's powerful and fun.
Thursday, August 23, 2012
Capture screen snapshot in MacBook
Try this
- Command + Shift + 3 => capture full screen.
- Command + Shift + 4 => then, highlight the area that you want.
Capture your face in MacBook
Double click on "Photo Booth" or call out Finder \ Application and then double click on Photo Booth.
Welcome to my iOS 5.0 development tips
Welcome!!
My blogging intention is to record down all the tips & tricks in iOS. It might not cover all the step by step tips for you.
Happy iOS development.
;)
My blogging intention is to record down all the tips & tricks in iOS. It might not cover all the step by step tips for you.
Happy iOS development.
;)
Subscribe to:
Posts (Atom)