how to modify this code - iphone

I read the post Add UIPickerView & a Button in Action sheet - How?
I want to add data to the uipicker view from nsarray , specially I have two buttons that they will call different two uipickerview , so I cannot use the delegate of uipickerview
also what is the code to clise this uipickerview
any suggestion please

– pickerView:titleForRow:forComponent:
If you use that method you are acctually being passed the appropriate pickerview... so you can work out what pickerview you are dealing with from that. Its the same with most of the other delegate methods. So use that to work out what picker view you are dealing with and change the content accordingly.
To get rid of the actionsheet you can do:
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];

Related

Custom UIAlertView?

Seeing as the blue doesn't go with my UI interface, im just wondering if there is a way to change the colour of the uialertview, or use a image instead. With all the buttons, 'dismiss' etc still there
Thanks
The fine folks at CodeCropper just put out an open-source control that lets you create custom alert views. It's awesome.
https://github.com/gpambrozio/BlockAlertsAnd-ActionSheets
You could try presenting a Modal View Controller with a transparent background.
ModalViewController *popupController = [[ModalViewController alloc] initWithNibName:#"ModalViewController" bundle:nil];
[self presentModalViewController:popupController animated:NO];
Something like this for the ModalView (http://stackoverflow.com/questions/849458/transparent-modal-view-on-navigation-controller)
This way you can create a custom Alert, but it's really a modal view that you can customize
You can either go through its subviews and change what you need to change, or subclass it. Because UIAlertView inherits from UIView you can use:
myAlertView.subViews
and modify the views or subclass UIAlertView to create your custom AlertView. Here is a very good article on how to sublass UIAlertView to get whatever design/color you want.
Subclassing UIAlertView
Basically what you want to override is this method:
- (void) drawRect:(CGRect)rect
Hope that helps.
you can use a uiview instead of uialertview and can easily customize uiview according to your needs
You could use CODialog. It's fully style-able and configurable.
Subclassing UIAlertView is not an option, this class is not intended to be subclassed and doing so might be a reason of app rejection.
Instead, you might try to go through all alert view's subviews or create your own class
In case you are going to create your own class, here's an example of how to fake UIAlertView:
http://iosdevtricks.blogspot.com/2013/04/creating-custom-alert-view-for-iphone.html
If looking for custom alert view then it might help.
https://github.com/Pradeepkn/PKCustomAlertView/
Hope it helps some one.
No need of setting delegate. You will get call back once the action completes on same method.
Enjoy :)
Custom Alert view
Table Alert view

SearchBar not working when search button is clicked

Can anyone help me out, i am working with UISearchBar and want that when i write anything in SearchBar and press enter key, it will start desired operation...
I have read searchBarSearchButtonClicked function will get called once the “Search” button will be clicked on the pop-up keyboard window. But it is not called:(
I have implemented as:
(void) searchBarSearchButtonClicked:(UISearchBar*) searchContact
{
//do some thing
}
i have checked by placing breakpoints infact this function is not being called....
any idea??
Thanks!!
Did you assign delegate to that viewcontroller which implemented "searchBarSearchButtonClicked" ?
You need to assign delegate like this.
searchBar.delegate =self;
You need to implement the UISearchBarDelegate protocol and set the delegate of the textfield to the class which implements this protocol.
This is the reason why the delegate is not getting called.
You can try this,
In IB set the delegate to file's owner and implement the delegate.
In Code, if you hold reference to the search bar, then on viewDidLoad
searchBar.delegate = self;

Close tableview in ViewBasedApplication

probably a very simple question but can't find the right answer anywhere. I am using XCode 4 and working on an iphone app, which probably sums up all the info that I need to provide.
Here it is:
- I created a ViewBasedApplication
- At some point depending on the user input, I load a TableView
But now how on Earth do I add a button or something to return? Note: I can't use a NavigationBased app, that would be easier but would not work for me.
Help anyone?
If you used a UITableViewController, you may want to use a UIViewController instead. In the UIVeiwController, you can add a UITableView along with your own UINavigationBar or, if you don't want to use a UINavigationBar, you could leave room for some type of custom UIButton. Either the UINavigationBar button or your custom UIButton action could trigger a close of your UIViewController.
If you add the UIViewController as a subview, then Cyprian's [self removeFromSuperView]; would work. If you present as a modal as Jamie suggests, you could use [self dismissModalViewControllerAnimated:YES];.
Well I don't know you code but you could always call
[self removeFromSuperView];

How to reload UIPickerView in iPhone?

hi
I am working on an iPhone app & i have to show some thing on a pickerview after receiving a response from socket, Methods of PickerView are check when application is going to be load. in my app i have to load PickerView on a button click.
After getting response in an array, When i click on button its shows a pickerview but empty. :(
SO can any body tell me how to reload the pickerview like tableView.
Thanx in advance
you could use either reloadAllComponents to realod all the component or reloadComponent to a zero-indexed number identifying a component of the picker view.
[myPickerView reloadAllComponents];
[myPickerView reloadComponent:IndexOfReloadComponent];
Read UIPickerView documentation
You can use below code, I hope it's work
[obj_Picker reloadAllComponents];
Call -reloadComponent: or -reloadAllComponents (methods on UIPickerView).
Quote:
You can dynamically change the rows of a component by calling the reloadComponent: method, or dynamically change the rows of all components by calling the reloadAllComponents method. When you call either of these methods, the picker view asks the delegate for new component and row data, and asks the data source for new component and row counts. Reload a picker view when a selected value in one component should change the set of values in another component. For example, changing a row value from February to March in one component should change a related component representing the days of the month.
Use this method - (void)reloadAllComponents of the UIPickerView class.

UIALertView customization

I am developing an iPhone application, in which I want to use customized alert sheet. The customization is required since I want to set image for Alert-Sheet buttons, change the size of these button etc.
I have done the following things:
Created UIView with customized controls that I wanted.
Created and displayed UIAlertView
In the delegate method of UIAlertView (UIAlertViewDelegate) i.e
- (void)willPresentAlertView:(UIAlertView *)alertView
I am removing all the subviews of UIAlertView and adding my customized view as subview.
Everything works fine till here. Since I have used customized buttons, I need to remove the alert sheet explicitly in the Action Method of the button by calling dismissWithClickedButtonIndex:animated: on UIAlertView.
Even though the UIALertView gets dismissed, it takes around 0.5 second to get dismissed.
Can someone help me out to solve the problem of this delay in dismissing OR some other way of customization of Alert View buttons.
Thanks and Regards,
Deepa
I could get it worked by passing YES to dismissWithClickedButtonIndex:animated: call i.e [alertView dismissWithClickedButtonIndex: 0 animated: YES]. Initially I was passing the flag as NO. But, I don't know whey it takes less time if we pass the animation flag as YES.
Anyone knows this?
Instead of doing this
/*
1. Created UIView with customized controls that I wanted.
2. Created and displayed UIAlertView
3. In the delegate method of UIAlertView (UIAlertViewDelegate)
*/
do this:
Create a class like this:
#interface CustomAlertView : UIAlertView
{
//For ex:
UIButton *myCustomButton;
//and other custom controls
}
Implement it in following method:
-(id)init
{
}
In the above method use:
[self addSubView: myCustomButton];
I have given just the idea. I have code but not presently to share with you.
If you are not able to implement the above I will provide later.
Thanks.
Here is the library which can solve your UIAlertView Customisation issue. It can also work as UIActionSheet. It has very good customisation options.
https://github.com/Codigami/CFAlertViewController