I would like to implement a view similar to the detail view of Apple's own Contacts app where it displays the name, phone number, note, etc. and its Edit mode.
Can you dissect how the whole view is done? Is that view done with a UITableView or a UIScrollView?
The contact details screen is actually quite simple to mimic.
Start with a UITableView and provide it with a UITableViewDataSource and UITableViewDelegate. You'll need to provide sections for all the data you want to present. This means 1 for the custom header, 1 for the custom footer (buttons / actions), and approximately 6 or so sections for the data (one section for phone numbers, another for e-mail addresses, and so on)
Inside of each section, a number of rows need to be provided from your datasource to indicate how much data there is for that section. For each row, a UITableViewCell can be used to display the actual contact data (fax label / fax number value, etc). You can get fancy if you like, but there doesn't seem to be a need. For things like ringtone you'll need to specify a disclosure indicator.
For the header you'll need a UIImageView and a UILabel, for the footer you'll need a few UIButtons. You can create a child of UITableViewCell in InterfaceBuilder with these views inside of it and wire it up like anything else. You can use NSBundle to load views from other xibs that are not already loaded.
An alternative is to dynamically generate the UI widgets at runtime with no xibs. It all depends on what you would rather manage (code or xibs), to me it seems about the same amount of effort either way. I highly recommend reading through the table view programming guide if you haven't already.
Or you could use Apple's own ABPersonViewController:
http://developer.apple.com/library/ios/#documentation/AddressBookUI/Reference/ABPersonViewController_Class/Reference/Reference.html
The allowsEditing property specifies whether the user can edit the person’s information.
My implementation uses a UITableView with custom header (for the "Add Photo" and edit name equivalents) and a custom footer (using the UISegmentedControl hack for a big button) for the "Delete" equivalent.
You can use F-Script for exploring this. Here's a screenshot from the F-Script browser while browsing Address Book. Basically, it looks like a lot of custom views which all inherit from NSView.
To do this yourself:
Download F-Script from the link above
Follow the instructions in the extras/F-Script Anywhere directory for attaching to Address Book
Choose F-Script -> Open Object Browser from the Address Book menu
Click Select View
Highlight the Address Book View you want to explore and click it.
Navigate around to your heart's content.
Just to show you the way, you can subclass UITableViewController for that purpose and then in order to implement the Edit mode similar to the Contacts app you would:
Add a property to store a reference to Cancel button.
var cancelButton: UIBarButtonItem!
In ViewDidLoad(), add edit button to the navigation bar as a right item and prepare Cancel button to later add it as a left item.
self.navigationItem.rightBarButtonItem = self.editButtonItem()
self.cancelButton = UIBarButtonItem(title: "Cancel", style: .Plain, target: self, action: "cancelPressed:")
Override setEditing(_:animated:) method to set up your cells for Edit/Preview mode and show/hide a Cancel button on the navigation bar, based on the editing flag.
override func setEditing(editing: Bool, animated: Bool) {
super.setEditing(editing, animated: true)
if editing {
// Set up cells and prepare for Edit mode here
self.navigationItem.setLeftBarButtonItem(self.cancelButton, animated: true)
} else {
// Set up cells and prepare for Preview mode here
self.navigationItem.setLeftBarButtonItem(nil, animated: true)
}
}
Override UITableViewDelegate's tableView(_:editingStyleForRowAtIndexPath:) and tableView(_:shouldIndentWhileEditingRowAtIndexPath:) methods to configure row styles and indentation when in Edit mode.
Implement cancelPressed method to exit Edit mode when Cancel is pressed.
func cancelPressed(button: UIBarButtonItem) {
self.setEditing(false, animated: true)
}
I know the question is pretty old, but somebody might find it helpful.
Related
Summary: I want to replicate the accessibility behaviour of a UIAlertView, where the background view is still visible but VoiceOver does not interact with it.
Detail: I have implemented accessibility for an iPhone app, but have one problem remaining. In some cases I display a large view on top of all others (partially transparent, covering most of the original view) containing labels and a close button. i.e. basically a custom popup/alert view. The problem is, VoiceOver continues to reveal the views/controls underneath it.
One method to prevent the hidden views from being revealed by VoiceOver is to set the whole custom view background to be accessible. However, this isn't really what we want as this containing view shouldn't really be interacted with by the user, only its subviews (labels/buttons) should.
I think you should use this on your top laying view:
Objective-C
- (BOOL)accessibilityViewIsModal {
return YES;
}
Swift
accessibilityViewIsModal = true
This makes every element of the View Controller that is hidden unaccessible.
An implementation could be to set it to true when you show the view and set it to false when you dismiss that view.
More info
Note: Requires iOS5 and up
Swift 4
In swift try this:
Before your view is presented setup your viewController’s view like this:
yourViewController.view.accessibilityViewIsModal = true
Also try setting the self.view.accessibilityViewIsModal to true in viewWillAppear
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
view.accessibilityViewIsModal = true
}
It also might help if you send a screen chances notification when your modal or pop up view is appearing by adding this to the viewWillAppear:
UIAccessibility.post(notification: .screenChanged, argument: nil)
You can set the following properties on the view overlaying the background:
view.isAccessibilityElement = false;
view.isAccessibilityViewModal = true;
Does this work?
In obj-c:
view.isAccessibilityElement = NO;
view.accessibilityViewIsModal = YES;
When you hide the item, you can set isAccessibilityItem to NO.
I would like to display a different view than the standard keyboard (a picker control, or a date picker, for example) when a text field becomes first responder (i.e. gets focus). This would be really nice, because currently I'm pushing a custom view which contains my picker control onto the navigation stack where the user chooses an option, and then hits an OK or Cancel button.
According to the documentation for UITextField.InputView:
Assigning a custom view to this
property causes that view to be
presented instead.
But, It's read only!!!
Is there a workaround for this? Do I need to implement a custom UITextField control and somehow override the InputView property? Do I need to call some kind of native function? I'd really love not to have to do either of those things... but if I have to, so be it. Thanks in advance!
The documentation is slightly out of date. There is a setter since MonoTouch 3.2.0.
Kevin's answer will work for UIKeyboardType keyboards but as far as I'm aware (I could be wrong) you can't present a custom keyboard this way.
The only way I know how to present a custom keyboard is to override the InputView for the UIViewController you wish to present the input view.
UIView keyboardView;
public override UIView InputAccessoryView {
get
{
// create the view as you'd like here
return keyboardView;
}
}
Wire up the UITextField to handle the appropriate editing event and in the event handler select the KeyboardType you want. If you don't need to dynamically set it then you can just set the property when you create the text field.
UITextField tf;
...
tf.KeyboardType = UIKeyboardType.PhonePad; // whatever kb you want
Im working on a small app that displays contact and biography details.
You can see two screenshot here: contactDetails, biogDetails.
At the moment I have an Action button on the right hand side of the NavigationBar that displays an ActionSheet where the user can perform various actions like:
"add to favorites"
"update data",
"Biog Details", etc.
I feel the "Biog Details" is not an action as the others and I would like to display it on a different way.
I was wondering if there is a way to add an extra custom button to the PersonViewController.
I dont really want to create a lookalike of the PersonViewController, because i would lose functionality that I can replicate with the public APIs.
The other option could maybe be to have a segmentedController on the center of the NavigationBar that would switch between the two viewsControllers. How could I do that?
Im open to ideas.
Thanks,
The only way you'll be able to add that extra button is if you use the UIToolBar instead of the UINavigationBar.
If you decide to use the UISegmentedControl you'll also have to use the UIToolBar.
You can duplicate the UISegmentedControl on both views but with the appropriately selected segment on either.
Or you could use one "base" view, add the other two as subviews and hide/unhide the appropriate view depending on the segment that is selected. This would however mean that you change the position of the subviews (by adjusting their rect parameters) so that they appear just below the UIToolBar
I've an application in which each row contains an uiimageview and an uibutton. I have created them using custom cells, uitableviewcells. The button is to trigger the method, uiimagepickercontroller to pick an image from the library and show it in the imageview. I need that any user who uses the application can rearrange the rows as they wish so that they decide the order of the photos. code here
Reordering of rows in a tableview is pretty straightforward, you just need to implement a few methods of the UITableViewDataSource Protocol and your good to go. Have a look at the Table View Programming Guide for info & code.
http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/ManageReorderRow/ManageReorderRow.html
You could show an Edit button in the navigation bar if your using a navigation controller, which switches the table view to edit mode, causing the reordering control to be shown. This edit button could be changed to done, once the table is in edit mode of course. Don't forget to set the showsReorderControl property of the cell to YES. From then on, it's just a matter of implementing the right methods.
I want to switch 3 views and let them switch from 1-2-3. The first view is to let users input name and password, the second view will show his information to let him confirm and the third view will show him a list of options so he can choose what to do next.
The problem is how to switch these views? If I use a navigation controll to switch views, how can I add textfield in it so users can input their infomation?
Thanks for your answers and I find this isn't so complicated as I thought earlier. After a few attempts, I finally made it. I just use NavigationController to switch between UIViews.
Now I understand that navigation controller can swith not only from UITableView to UIView, but also from UIView to UIView. Using a UIView class, I can organize all the controls easily in IB.
Check out Apple's sample TableViewSuite application for hints. You'll find more sample code at Apple's iPhone Developer site.
You hate to write your code into
-(void)IBAction
set the button property by using connection Inspector set the button to touchesDown.
After this the view which you want to see at the beginning. Make it's alpha value 1 and other view's alpha value should be 0. After filling all information when you will click on button. Make alpha value of first view should be 0 and the second view's alpha should be 1. Like that you can proceed