NSDictionary from P-list with UIPickerView - nsarray

I'm having a problem with my picker in one of my apps. I have an NSDictionary obtained from a property list that contains a bunch of keys, which in turn contain a bunch of strings. I have two components, each one should have the same list of strings within. I also have a slider that I want to use to allow the user to change keys. So when the slider's value goes from 0 to 1 the key at index 1 in the dictionary should load its contents into the pickerview's components.
It's working as far as loading the new contents into the picker based on the slider. I've been using the slider's tag as the variable to dictate which contents get loaded. The problem is that after loading a new list of items the program crashes, I'm thinking that the number of rows needed isn't getting update or something but I'm just not experienced enough with UIPickerView to isolate the problem myself without spending more hours than I've already used trying to figure this out myself.
Here are my delegate/data methods for the picker:
#pragma mark -
#pragma mark Picker Delegate/Data Methods
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
//aryNames is an NSArray instance variable that contains the values for the components of the picker
if (component == 0)
return [self.aryNames count];
return [self.aryNames count];
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
//I think this is where my problem is
//I'm using a string to select the object
// at the index of the slider's location to
// fill up the instance variable with new data.
//Anyway, it works fine if I have two different arrays hardcoded
//but I'd really like to have this load dynamically because
//there are a lot of keys and this way I could add and remove keys without
//worrying about changing code
NSString *selectedType = [self.aryKeys objectAtIndex:slideUnitTypes.tag];
NSArray *newNames = [dictAllNames objectForKey:selectedType];
self.aryNames = newNames;
return [aryNames objectAtIndex:row];
}
//I'm pretty sure that the method below is not the problem
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:
(NSInteger)component
{
if (component == 0)
{
[firstValueHeading setText:[aryNames objectAtIndex:row]];
}
else
{
[secondValueHeading setText:[aryNames objectAtIndex:row]];
}
}
If it wasn't descriptive enough or you need to see more of my code please tell me. This problem has been a real bugger in an otherwise smooth project. Thanks.

I am still fairly new to this myself, but in Troy Brant's book (chapter 9) he does this. You should grab the book from the library/bookstore and review the source code at http://troybrant.net/iphonebook/chapter9/Ruralfork-done.zip
It should help.

i've actually solved this long since. here is the code for that delegate if it helps:
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSUInteger index = slideUnitTypes.value;
NSString *placeString = [self.aryKeys objectAtIndex:index];
NSArray *returnThisArray = [dictAllNames objectForKey:placeString];
return [returnThisArray objectAtIndex:row];
}
if anyone out there needs to see any of my other delegates just comment on this answer and hopefully SO should send me an email.

Related

How to make an Action that opens a page that is filtered after multiple option values in AL?

I'm pretty new to business central so excuse me if this is a rather stupid question. I have been trying to make a button that sends the user to a page where he can see products that are new or old.
A product has a field named "Status" which can have the values "New", "Old", "SoldOut" or "BeingDelivered".
So my question is how do I set the filter to only show products that are either "New" or "Old". I got this so far which only shows products that are "New" but I can't figure out how to show "New" OR "Old" ones.
Group(group1)
{
Action(testAction)
{
ApplicationArea = All;
Caption = 'TestAction';
RunObject = page Products;
RunPageLink = Status = const("New");
}
}
I have been trying to find a solution and tried a bunch of different approaches but couldn't figure much out. Any help is really appreciated.
Little Edit:
Here is an example of what I would ideally want which obviously doesnt work though.
Group(group1)
{
Action(testAction)
{
ApplicationArea = All;
Caption = 'TestAction';
RunObject = page Products;
RunPageLink = Status = const("New|Old");
}
}
Thanks for your time and effort!
Use filter instead of const
Cheers

Scout Eclipse check for dirty fields

When you try to close Swing application and you change same value in field, application ask you if you want to save changes.
My first question is why RAP application doesn't ask same question ?
Second and more important question is how to force validation of fields change and how to manipulate this.
for example :
I have table with rows and some fields below table. If I click on row some value is entered in fields. I can change this value and click button save.
I would like to force change validation on row click. So if changes ware applied and if I click on row, application should warn me that some changes are not saved.
But I should be able to manipulate what is change and what is not. For example if table on row click fill some data if fields this is not change, but if I entered value is same fields this is change.
I discovered method
checkSaveNeeded();
But it does nothing. (if I change values or not)
I see that every field has mathod
#Override
public final void checkSaveNeeded() {
if (isInitialized()) {
try {
propertySupport.setPropertyBool(PROP_SAVE_NEEDED, m_touched || execIsSaveNeeded());
}
catch (ProcessingException e) {
SERVICES.getService(IExceptionHandlerService.class).handleException(e);
}
}
}
so I should manipulate changes throw m_touched ?
How is this handled in Scout ?
ADD
I am looking for function that check for dirty fields and pops up message dialog, same as when closing form, and way to set fields dirty or not.
I look here and here, but all it describes is how values is stored for popup messages and dot how to fire this messages (validation).
My first question is why RAP application doesn't ask same question ?
I am not sure to know which message box you mean but it should be the case.
There are several questions about unsaved changes and form lifecycle in the Eclipse Scout Forum. I think you can find them with Google.
I have also taken the time to start to document it in the Eclipse Wiki:
Scout Field > Contribution to unsaved changes
Form lifecycle
I think you should implement execIsSaveNeeded() in the corresponding field. The default implementation in AbstractTableField uses the state of the rows, but you can imagine the logic you want.
#Order(10.0)
public class MyTableField extends AbstractTableField<MyTableField.Table> {
#Override
protected boolean execIsSaveNeeded() throws ProcessingException {
boolean result;
//some logic that computes if the table field contains modification (result = true) or not (result = false)
return result;
}
//...
I hope this helps.
I am looking for function that check for dirty fields and pops up message dialog, same as when closing form.
Are you speaking from this message box that appears when the user clicks on Cancel in the form?
There is no specific function that you can call for that. But you can check the beginning of the AbstractForm.doCancel() function. It is exactly what you are looking for.
I have rewritten it like this:
// ensure all fields have the right save-needed-state
checkSaveNeeded();
// find any fields that needs save
AbstractCollectingFieldVisitor<IFormField> collector = new AbstractCollectingFieldVisitor<IFormField>() {
#Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
if (field instanceof IValueField && field.isSaveNeeded()) {
collect(field);
}
return true;
}
};
SomeTestForm.this.visitFields(collector);
MessageBox.showOkMessage("DEBUG", "You have " + collector.getCollectionCount() + " fields containing a change in your form", null);
I have changed the Visitor to collect all value fields with unchanged changes. But you can stick to the original visitField(..) implementation. You cannot use P_AbstractCollectingFieldVisitor because it is private, but you can have a similar field visitor somewhere else.
I am looking for a way to set fields dirty or not.
As I told you: execIsSaveNeeded() in each field for some custom logic. You can also call touch() / markSaved() on a field to indicate that it contains modifications or not. But unless you cannot do otherwise, I do not think that this is the correct approach for you.

How to remove elements from an Ember.ArrayController

In JavaScript, one can remove selected elements from an array by traversing it in reverse order and using splice(index, 1) to remove undesired elements. I'm trying to figure out how to do the same thing in Ember.js (without Ember Data).
I have an ArrayController and the associated Route's model function simply returns a JavaScript array. There an action in the controller, along the following lines:
removeElements: function () {
var i, arr = this.get('content'),
i = arr.length;
while (i) {
i -= 1;
if (arr[i].get('flag')) {
array.replace(i, 1);
}
}
This first appears to work in the browser. For example, if I have three elements and mark the first and third to be removed, the browser will leave the second item displayed. However, if I later try to mark the latter, Ember complains with Uncaught Error: Can't remove an item that has never been added.
I used replace() because Ember arrays don't have a splice method, but the docs also say that replace must be implemented in order to be used, but I don't quite understand where I'm supposed to implement it and I haven't found any sample implementations to guide me.
I've also tried various other methods, such as removeObject, removeObjects and more, but none did what I need.
You'd need to create your own array collection and implement replace on that collection (probably extending Ember.Array to get you started).
removeObject should work just fine (granted a little inefficient, though if the size of this list is small it's negligible):
removeElements: function () {
var controller = this,
list = this.toArray();
list.forEach(function(item){
if(item.get('flag')){
controller.removeObject(item);
}
});
}
using removeAt should give you the results you're looking for
removeElements: function () {
var i = this.get('length');
while (i--) {
if (this.objectAt(i).get('flag')) {
this.removeAt(i);
}
}
}

Search Dialogs in Epicor

Hopefully someone here is familiar with creating customizations in Epicor 9. I've posted this to the Epicor forums as well, but unfortunately that forum seems pretty dead. Any help I can get would be much appreciated.
I've created a customization on the Order Entry form to display and store some extra information about our orders. One such field is the architect on the job. We store the architects in the customer table using a GroupCode of AR to distinguish them from regular customers. I have successfully added a button that launches a customer search dialog and filters the results to only display the architects (those with GroupCode AR). Here's where the problems come in. I have two questions:
1: On the customer search, there is a customer type field that defaults to a value of Customer. Other choices are < all>, Suspect, or Prospect. How can I make the search form default to < all>?
2: How do I take the architect (customer) I select through the search dialog and populate its CustID into the ShortChar01 field on my Order Entry customization? Here's the code I have:
private void SearchOnCustomerAdapterShowDialog()
{
// Wizard Generated Search Method
// You will need to call this method from another method in custom code
// For example, [Form]_Load or [Button]_Click
bool recSelected;
//string whereClause = string.Empty;
string whereClause = "GroupCode = 'AR'";
System.Data.DataSet dsCustomerAdapter = Epicor.Mfg.UI.FormFunctions.SearchFunctions.listLookup(this.oTrans, "CustomerAdapter", out recSelected, true, whereClause);
if (recSelected)
{
System.Data.DataRow adapterRow = dsCustomerAdapter.Tables[0].Rows[0];
// Map Search Fields to Application Fields
EpiDataView edvOrderHed = ((EpiDataView)(this.oTrans.EpiDataViews["OrderHed"]));
System.Data.DataRow edvOrderHedRow = edvOrderHed.CurrentDataRow;
if ((edvOrderHedRow != null))
{
edvOrderHedRow.BeginEdit();
edvOrderHedRow["ShortChar01"] = adapterRow["CustID"];
edvOrderHedRow.EndEdit();
}
}
}
When I select a record and click OK, I get an unhandled exception.
I think the problem you are/were having is that you aren't adding the CustNum to the Sales Order first. In my mind I would do it this way first, but there is might be ChangeCustomer BO method in oTrans that you could call to make sure everything defaults correct.
EpiDataView edvOrderHed = ((EpiDataView)(this.oTrans.EpiDataViews["OrderHed"]));
if (edvOrderHed.HasRow)
{
edvOrderHed[edvOrderHed.Row].BeginEdit();
edvOrderHed[edvOrderHed.Row]["CustNum"] = adapterRow["CustNum"];
edvOrderHed[edvOrderHed.Row]["ShortChar01"] = adapterRow["CustID"];
edvOrderHed[edvOrderHed.Row].EndEdit();
}
Hope that is helpful, even if late.

Word automation with C++ Builder 5

I'm trying to control Word through a c++ builder 5 application. I would like to
open a ".dot" model file created with Word and modify it. In the ".dot" model file
there are some fields. For example, Title, LastName, FirstName, Address
and so on, and I would like to modify these fields putting text into them and then
saving file with a new name, for example "Warning.doc" leaving the ".dot" file
unaltered.
I can open the file, count the number of fields it contains, but then
when it comes to replacing each field with a string I don't know how to do because
I don't have a complete documentation on OleFunction and OlePropertyGet methods. I attach my source code to this message, can anybody help me to solve this problem please?
try
{
my_word = Variant::CreateObject("word.application");
}
catch (...)
{
Application->MessageBox("Unable to obtain Word automation object",
"Error:",MB_OK | MB_ICONERROR);
}
my_word.OlePropertySet("Visible", (Variant)true);
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Variant this_doc;
Variant my_fields;
Variant test;
int k,field_count;
AnsiString test1;
AnsiString filename = "d:\\ProgrammaWord\\1-Avviso.dot";
my_docs = my_word.OlePropertyGet("Documents");
this_doc = my_docs.OleFunction("Open", filename);
my_fields = this_doc.OlePropertyGet("Fields");
field_count = my_fields.OlePropertyGet("Count");
for(k = 1; k <= field_count; k++)
{
test = my_fields.OleFunction("Item",(Variant)k);
test1 = test.OleFunction("Value"); //This instruction throws an exception
// "Value" is not a recognized parameter
// in this case
Memo1->Lines->Add(test1);
}
}
I never used word Ole but I used it for Outlook and Excel, I can't try it with word since I'm currently on OSX but you should try something similar as what I did.
The generic way of using Ole was to OleGetproperty() while you get the targeted field then OleSetProperty("action", ...).
for example when I wanted to change the color of the text in a particular cell of my excel document I used:
Variant _excel = Variant::CreateObject("Excel.Application");
Variant _workbook = _excel.OlePropertyGet("WorkBooks").OleFunction("Open", filename);
Variant _worksheet = _workbook.OlePropertyGet("WorkSheets", sheet);
_worksheet.OlePropertyGet("Cells", row, col).OlePropertyGet("Font").OlePropertySet("Color", color);
Here I instanciate an excel object, then I load a file into it (_workbook), then I select the _worksheet from the _workbook and I start my business.
Here comes the interesting part:
It concist of getting to a particular cell, getting the font object from it, and then setting the color of this font object.
Disclaimer: This is an example from my sources for excel, it's not directly related to your example, but maybe you can understand the principe with it. I can't try to figure out what you need because I have no windows right now.
Hope this can help you. Finding ressources for OLE can be fierce if you don't have the good patterns to look for.