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
Related
I want to make "tableViewcell.selection = .None" , either by storyboard or code with minimum lines. I have tricks to do it, but I really willing to know if there is any other easiest possible way exist which I may missing in the apple documentation.
I am working with below components:-
UITableViewController
UITableView (Static)
UITableViewCell (no IBOutlet connected because its not required for my simple implementation)
Subviews of UITableView has IBOutlets
In .swift, didSelectForRowAtIndexPath defined because I want user interaction on click (no delegate method called because so far not required)
Is there any way to disable cell selection from storyboard.
Set the selection style of cell to None in storyboard.
Refer this:
https://developer.apple.com/reference/uikit/uitableviewcell/1623221-selectionstyle
I do understand how to go about making the UIKeyboard push up the UIView if the active UITextView is blocked by the UIKeyboard as per this question: How to make a UITextField move up when keyboard is present?.
What I'm wondering is, from a design perspective, how do you go about implementing the keyboardDidShow and keyboardDidHide methods so that all of the views in your app, whether they be a UIView, UITableView, or UIScrollView all have this functionality and so you need to implement these methods only once?
The only way I could think of would be to have the view property of the UIViewController always set to a UIView, and if you have a UIViewController that needs a UIScrollView or UITableView, just attach it as a subview to this. Then if the UITextView is being blocked, just move the parent UIView up so it will move all of the views that are attached to it.
Does this sound like a good plan, or is it even worth it? Anyone else have any other ideas?
This is a little old, but it's a great article about using firstResponder methods to tell views to slide up. I, personally, like to put my UITextField in a parent container and move it all up. However, I do NOT suggest putting everything in there and moving it all up, because the UITextField "feels" better just above the keyboard. But I do like the background or certain items to move up with the UITextField.
See below: http://cocoawithlove.com/2008/10/sliding-uitextfields-around-to-avoid.html
This is a nice implementation that moves the field up based on the section of the screen it's in (upper, middle, lower). Works very well. May need to be updated for newest SDK, but should be pretty easy.
In experimenting with this, I noticed that if you want to make a BaseViewController that implements this functionality to work for everything that inherits from it, you have to attach another view on top of the UIViewController's view property in order to get it to work. Reason is, if you push the UIViewController's view property up when the keyboard appears, then it resets itself if the app comes back from being active and it's messy.
The problem with this however, is now in all of your child classes you have to attach your subviews to this new view property instead of the regular view property. Also, you probably have to make a custom UITableViewController which will inherit from your BaseViewController class so it can inherit the keyboard notification methods.
Ultimately, I've found it's not the worst idea to have another view on top of the UIViewController's property for a bunch of different scenarios. Making a custom UITableViewController isn't that big of a deal either. So if you have a lot of text fields in your app, this might not be the worst way to go.
So I don't know what the best way to follow MVC is. Similar to the address books app, I want to have a UITableVeiewcell that has the ability to edit notes. I figured I would do that with a UITextView in a UITableViewCell subclass. My subclass has just that as a property, and a label that says "notes". I can see a few use cases that I need to consider,
1) when they are done editing and click outside or hit return.
2) when the text goes beyond the size of the cell I need to resize the cell.
Because my UITextView is in IB, is there a good way to define the delegate methods for the UITextView since my UITableView is in another ViewController subclass? Like how do I pass that information back?
Or, is it better to create my UITableViewCell subclass in code since it's just a couple of items so all my delegate and resizing code is done in the view controller class?
Thanks!
After text field editing was finished, you can store it's value in some dictionary in your controller. You can use cell's indexPath as key in this dictionary. In such way you will not lose your data with dequeue cells.
To resize cell you must call reloadData method and change rowHeight property of entire tableView or implement tableView:heightForRowAtIndexPath: delegate method to set needed row height to current cell.
I haven't use UIKit since iOS 3.1, so the second part of my answer can be out of date, but I hope it will help you =)
At the moment, I have a settings view in my iPhone app built with Interface builder, it consists of a background image, some text fields, labels and buttons. Because this looks bad, I want to convert the settings view to an UITableView with custom UITableViewCells.
I already tried adding some cells into my settings view's XIB and returning them in the cellForRowAtIndexPath method (with [return myCell];), as written in Apple's tutorial, but this was not working for me - my whole TableView looked strange and it only showed the first cell correctly.
Is it possible to design these custom cells in Interface Builder? Do I have to create an empty XIB for them or can I put them in my view's XIB? And how do I insert them into my TableView?
Thanks in advance,
Yassin
You can absolutely add custom table cells that you built in interface builder. This includes both static cells and Dynamic cells. However without you providing more information the best I can say is "double check the docs and try again." I can only say that it works and it's rather straightforward so it's hard to say what you may have missed. It might be more helpful if you post what you have for the tableView:cellForRowAtIndexPath method.
Since you say you just have some text fields, I would recommend looking at the technique for static row content section of the Table View Programming guide. You probably would want to have each field of your form correspond to a row in a Segmented Table View, it'll make everything look nicer.
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.