i have 2 tableviews in my application with 5 UISwitch in each view.For every switch there is an action.Now i decide to change the label text of switch.I was able to change the label text from ON_OFF to YES_NO .
But after implementing this method in a seperate class which is a UISwitch class i am not able to call the action method for that particular switch.The same is working well if i doesn't implement this method to change the label text.
Can anybody suggest me that were i am going wrong.
You should post some actual code; particularly how you changed the label text. Are you using undocumented APIs? The UISwitch class reference specifically says it's not customizable.
When you say things like "implementing this method in a seperate class which is a UISwitch class," do you mean you've subclassed UISwitch? This also isn't supported. It's a clunky control and there's not a lot that can be done about it without building your own.
Related
Currently i am working to create a mail composer view without using MFMailComposerview.
My requirements are that i should have to,cc,bcc fields with a webview as as body, while zooming the webview its should behave in the same way as native mail behaves, i.e the "to,cc,bbc" field should also move proportionally.
Concern is just related to the UI not functional part.
Any suggestions on how to start with this thing.
Regards,
Suhail
For UI Part (XIB), you can start with following:
You can have a ViewController subclass with UINavigationBar.
Add UITableView (of plain style) on that UIViewController
Make UITableViewCell custom subclass for To,CC,BCC fields.
Make another UITableViewCell custom subclass for Contents.
For the last point, You can use UIScrollView having UItextView and/or UIWebView based upon your requirements for the content/body of your email.
After all this, UI Components working as per your expectation; you can move on the functional part, which is define (though in broad sense) in #user2235613's answer.
Good luck.
I am building a custom control that looks like the one in the image below.
It will basically be a menu with a slider. The arrows will allow me to change the three days show on the slider track. Acoording to the day I select with the slider I want to change some views on the main screen (this menu will on the bottom of my page). So basically this is the only thing that I will "listen" in my main controller: if some day has been selected.
I have figured out all the code I will have to write, but I am not sure wether I should subclass UIControl or UIView. And if so, where should I write the code of my controller (changing the days, adding the drag effec, etc ) in the UIControl (UIView)? Or should I subclass UIViewController, and write there all the code there. (but if so, why should I subclass UIControl (UIView) in the first way).
So basically I want to know what extra files I need to create, besides the view interface of my custom control(which I did in the IB), where should I put the code (IBOutlets, IBAction methods) and how do I communicate with the main view controller (I set the main controller as a delegate of my custom control?).
Sorry for the long post.
Thanks
I recommend to subclass UIControl. Users of this control can do [yourControl addTarget:self action:#selector(someMethod:) forControlEvents:UIControlValueChanged]; to react to changed values. In your control, when you have determined that a new day has been selected, you call [self sendActionsForControlsEvents:UIControlValueChanged]; and voila, all interested classes will get informed.
Keep that control as self-contained as possible. This means, only give it as much logic as you need to, and nothing more. Think about how you use Apple provided UI elements: try to make yours as generic (if practical; use common sense here). In short: you should thrive to make this control generic enough that it could be useful to you in other projects or other places of your app.
The short answer is you should subclass UIControl and put all of the logic to draw the component and interact with the component there. UIControl inherits from UIView and adds target/action behavior. This way you can sendAction:to:forEvents: with UIControlEventValueChanged whenever the date changes.
You could alternatively implement a delegate protocol for when the user changes the selected date.
For example:
#protocol DateSliderDelegate <NSObject>
- (void)dateSlider:(id)slider dateDidChange:(NSDate *)date fromDate:(NSDate *)oldDate;
#end
You don't want to use a UIViewController since it's job is to manage higher-level views, like the screen that your widget is on. You'll use a view controller later when you are consuming your component and do things like set the date to display initially and listen for change events.
I'm looking through the TableSearch example code provided by Apple. In the cellForRowAtIndexPath method, depending on if an item is being searched or not, the table gets updated. I was wondering if this type of functionality can be implemented without using a UITableView. I'm tryign to copy that functionality with a horizontal display of cards. Thinking out loud, assuming this is possible, I would
have my horizontal display of cards have a delegate that can be called when something is typed in the search bar.
would i subclass UISearchBar to add this delegate, so I could do
something like searchBar.myNewDelegate = horizontalDisplay;
No need to subclass, just make your controller conform to the UISearchBarDelegate protocol and you can implement all of the text did change methods to do what you want.
http://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UISearchBarDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UISearchBarDelegate
So in my code I used the setAlternateColor: method on my UISwitch to change the color to orange but my app got rejected because of this.
So I decided to use photoshop to create a custom UISwitch. Now that I have the image how am I supposed to get the UISwitch to use my custom .png?
You can't. It's probably easiest to write your own custom switch class. It's not very hard to subclass UIControl and reimplement the few things UISwitch does. (I don't know if it would also work to subclass UISwitch directly and override drawRect:. Might be worth a try.)
I'm wondering if it's possible to add an ivar to the UIButton class? A bit like categories but not for a method(s) but for ivars.
I am programmatically creating and displaying an array of UIButton's which I then all link up to a single action method using –addTarget:action:forControlEvents: for a touchup event.
Now, my receiver method needs to know which of all the buttons was pressed but using the "(id)sender" approach doesn't cut it because the only thing differentiating all the buttons is the image its displaying and there is no way to get to that (I need a string). The buttons are all in different places so I could do some math to convert the position data into an "id" but if I change the positioning of the buttons down the line, I will need to change the math as well and I don't like that.
Can I just subclass UIButton and change nothing except for adding a (NSUInteger)idCode property? Then when I create the buttons I set the idCode, and when the target-action mechanism fires the action method, I can just do sender.idCode. Is this the way to do it?
Is there a better standard/elegant way of implementing this kind of multiple target-action see-where-it-came-from behaviour?
P.S.: Is there a quick way to type the backtick on a Mac?
You could do it this way. But this is not necessary - every UIView (and subclasses which includes UIButton) has the tag property which is just what you want.
UIButton as well as all UIView subclasses already has an integer property for exactly that purpose: tag