Can I use multiple lines of text in a UIAlertView's button? - ios

At one point in my app, the user has to choose from a list of reasons (it's a medical app that lets one user check if another user gives a patient the right medicine and dose via one or more photos). If the photo is rejected, the user has to choose a reason.
One of our customers provided a list of possible reasons, and they can't be changed. The problem is that one of these reasons is a very long sentence and when I add it to the alertview, the text gets really small instead of just wrapping to a new line. I tried putting a \n in my string, but then the second line isn't shown (so it does work, but I only see the first line in the view).
Can I add multiline functionality to the alertview's buttons? I know a UIButton does not support multiline. I also know UIAlertView's addSubView: does not work anymore since iOS7. I'd rather not use any third party libraries, but if I really have to I'm open to suggestions. Increasing the size of the alertview would be an option as well.

For your requirement it will be better if you use UIActionSheet or Customized PopUp View where you can use multiline.

UIAlertView and UIActionSheet are really meant to provide concise feedback and make concise decisions respectively. It sounds like you need a richer interface for the user to make a selection. I would suggest that you create a custom UITableViewController class with a dynamic cell that presents a set of reasons and allows selection of a reason. You could dynamically create a non-editable UITextView to display a multi-line reason and perhaps a button next to the reason to select it. Each row of the UITableView would contain a UIButton to select and a UITextView to show the reason. In your UIableViewController class you would assemble all the reasons relative to the context and then present them in the table view for selection - one row for each possible response. Alternatively, you can forgo the button and just present the reasons via a UITextView. If the user clicks on the row (table cell) you can indicate the response with a check mark
cell.accessoryType = UITableViewCellAccessoryCheckmark;
and capture the selection for processing in
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Reason *selectedReason = self.myReasonsArray[indexPath.row];
}
enter link description here
Also, UIAlertViews do not support subclassing and have very limited configuration capabilities. I'm suggesting you accomplish your objective by creating a "custom" modal view via a UITableViewController that can be used to essentially popup a rich interface that allows you to do all sorts of things like have multi-line text, images, whatever. You can reuse this view everywhere via delegation.

Related

How can I give a particular behavior to a UITableViewRowAction?

I have a standard UITableView of items. Tapping a row will bring a DetailsViewController with details about the selected item and the possibility to use it through a UIButton.
I have implemented the (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath method made available from iOS 8 and I defined two actions:
The standard deletion of the item (pretty simple stuff).
The possibility to use the item like above. I basically want this action behavior to be the same of the IBAction related to the button in the DetailsViewController.
I thought about presenting this view controller automatically and making an automatic tapping of the button without using interaction, but this could be a bit confusing for the user according to me. So I would prefer to call the IBAction method directly from the table view controller. Is it possible and how can I achieve this result?
I can provide the source code if this could help you to help me.
What you need to do is take the "use this thing" action out of your ViewController, and put it in the Model object for "thing."
Then, when you want to use your "thing" from the tableView or the DetailsViewController, you can call this function directly on the associated model object, and allow your two (possibly more) different user interfaces to perform the "use that thing" functionality appropriately based on their own UI needs.

how to connect textfield with table view of listed options instead of keypad

I need to be able to disable the keypad in a textfield, and instead when the user taps on it to start editing, a new table view will appear presenting a list of possible strings with which the textfield should be filled.
Anyone has any suggestions on how to achieve this?
Thanks in advance
p.s. I tried already but this functionality cannot be nicely implemented with a picker in my case, as there are too many options to choose from and (more importantly) each one of them is a rather long string and cannot appear entirely in a picker.
I believe you just need a regular cell that, when tapped, pushes a new detail UITableViewController with all the options to choose from. Once an option is chosen, set the cell's textLabel to whatever option have been selected.
If you'd like to go for an easier path, then you should also probably check the free Sensible TableView framework, as it has these kinds of cells out of the box (called selection cells). You just pass on your strings array to the selection cell and it will automatically display the detail view, and even assign the selected option to one of your object's properties if you wish. Should save you some good amount of manual work. Good luck!

Table View Design Issue

My app design required a page that display 'user information' and i currently have this setup using a simple table view in a View controller. Now, the tricky thing is I need to be able to provide functionality to the user to be able to edit these on the same same screen. So essentially when the user taps on a row in the table view, I want that little flashing text line at the end of the current text in the row so the user can edit what's currently present and I also want a save button to apear on the top when a user has started editing. The tricky part is, not all fields in my table view will be editable. So, I need certain fields to be editable and have the save button appear and certain fields not.
Can you tell me how would I go about modifying my existing design to implement this functionality? I would appreciate some code if you think you can show me how exactly I would go about doing things.
You would probably want to make some custom UITableViewCells. You can fill a tableview with all sorts of different cells which are different sizes and looks different, all at the same time. I would suggest a custom UITableViewCell which will hold a UITextField as one of the subviews. On the cells which you don't want user interaction with the textfield, either make a new custom cell that uses a UILabel or just do textfield.userInteractionEnabled = NO. Look up some custom uitableviewCell tutorials to get you started and then use the approach that I suggested for your problem.

iphone/ipad how to handle lots of input fields?

I'm writing a app that contains quite a bit of input fields for collecting data.
and im wondering what are some good methods to display these kind of input fields, if there are too many to fit on a screen? so something like the add contact screen... where u can scroll down and there are fields there
my initial idea is to put them in a scroll view and then i can scroll through them, is there a tutorial to do this? it seems like the scroll view is more for dynamically displaying data like a text view, and not for static forms like i was describing.
if anyone has any different methods for doing this please post.
UITableview will match perfectly for what you need.
My friend wrote this which is a container view that automatically helps with moving fields out of the way of the keyboard - It will certainly save you some time if you don't want to use a UITableView:
https://github.com/mackross/GTKeyboardHelper
The other way as H2CO3 suggested is to use a UITableView. If it is a UITableViewController, then you get the moving out of the keyboards way automatically. You could build custom table view cells that are styled to have a prompt and a UITextField for input. You can also set the selectionStyle to UITableViewCellSelectionStyleNone to prevent these cells from highlighting when selected.
I think the third way is to do this with a UINavigationController (or a UIPageControl) and build a kind of wizard, where you go through various pages of related data. This might be the neatest way depending on how many fields you have and if you can group data into common sets (e.g. personal information, work information etc)
I had the same problem and found GTKeyboardHelper to be an easy way out.
After drag and drop the framework in your project, include the header file.
Download and open the example project, then drag the "Keyboard Helper" object from the objects section in the xib to the objects section in your project's interface builder.
Drag and drop all your views to be children of the "Keyboard Helper".

How to make buttons on UIAlertView displaying in multiple lines?

I want to display a message using UIAlertView and there will be two buttons. As one of the buttons has a long name, It's not appropriate to display both of them in one line. I know that when there are more than two buttons, all of them will be displayed each in a row. How can I display these two buttons in two line?
Thanks.
There is no officially documented way to do this.
UIAlertView is a subclass of UIView. So you could traverse its subclasses to find the buttons, and transform their position and size. This is probably a bad idea though. If Apple changes it's implementation of the UIAlertView, it might break your code. Your app might also be rejected for customizing the UIAlertView. Eg see this answer.
Instead, you should consider changing the title of your button to be shorter, or create your custom UIView subclass that you present modally.

Resources