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:.
Subscribe to:
Posts (Atom)