I am trying to adding constraints for one view in cell.
This is my code :
let labelView = UIView()
let labelItem = UILabel()
labelItem.text = menuList[indexPath.row-1]
labelItem.textColor = UIColor.white
labelView.addSubview(labelItem)
cell.addSubview(labelView)
labelView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint(item: labelView, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: cell, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: wCell).isActive = true
NSLayoutConstraint(item: labelView, attribute: NSLayoutAttribute.leading, relatedBy: NSLayoutRelation.equal, toItem: cell, attribute: NSLayoutAttribute.leadingMargin, multiplier: 1.0, constant: 10.0).isActive = true
But, it error "libc++abi.dylib: terminating with uncaught exception of type NSException". Can you help me? Thanks a lot
I believe the method of adding constraints programatically has been changed in Swift 3, see more information here:
https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/ProgrammaticallyCreatingConstraints.html
Related
This bit of Code here creates a scrollview of buttons to allow me select from a list of different "tickets"
SearchResultButton(Button(text=str(Datarray2[i]),id=str(Datarray2[i]),on_press=self.Pressbtn ))
self.ids.SearchResult.add_widget(SearchResultButton)
From there it opens this function, which should set a variable (In this case "UpdateTicketNum") which will be used in another function to set the label text in another screen.
def Pressbtn(self, SearchResultButton):
global UpdateTicket
UpdateTicket = OPENTicket
woo = SearchResultButton.text
print(SearchResultButton.text)
wow = [blank.strip() for blank in woo.split(',')]
print("\n\n\n\n")
global UpdateTicketNum
UpdateTicketNum = (wow[0])
self.manager.get_screen('UpdateTicket').UpdateOpen()
At this point it opens up the sqlite DB and double checks that the TicketNumber is valid. The issue comes in when trying to access the label inside the kv build
def UpdateOpen(self):
print("TESTSETST")
conn = sqlite3.connect('TicketData.db', timeout=10)
UD = conn.cursor()
UD.execute('SELECT TicketNumber FROM TicketData WHERE TicketNumber = ?',(UpdateTicketNum,))
tips = UD.fetchone()
print(tips[0])
tipsy = tips[0]
UpdatedLabelTexT = tipsy
sm.current=('UpdateTicket')
UpdateTicket.ids.UpdateLabels['text']=(UpdatedLabelTexT)
The UpdateTicket.ids.UpdateLabels['text']=UpdatedLabelText] field always claims to be a property of the scrollview buttons even though I am initializing it inside another class, and with different parameters. apologies if this question is poorly formatted. but 3 days of dying trying to figure this out and I snapped.
Here is the bit in KV
<UpdateTicket>
name: 'UpdateTicket'
on_enter:
root.UpdateOpen()
orientation: "vertical"
FloatLayout:
canvas.before:
Color:
rgba: .0, .6, 1, 1
Rectangle:
pos: self.pos
size: self.size
source: "lights.jpg"
Label:
id: UpdateLabels
text: "filler"
multiline: False
size_hint: (None, None)
size: (root.width/5,root.height/20)
pos_hint:{'center_x': .5,'center_y': .5 }
and how I initialize the screen
sm.add_widget(UpdateTicket(name='UpdateTicket'))
I found the solution that worked for me. when first initializing the app
class SampleApp(App)
return sm(to build the application)
I needed to replace that return SM with
global root
return sm
root = ScreenManager()
return root
And that appeared to fix my issue. thanks for reading
Image with large alert box
I have a situation where the alert box shown on the screen with the message is too large (default size). How to customize the size of the alert box?
Class: aWFErrorFixer
Method: AlertWithErrors
procedure AlertWithErrors(customMessage : CString)
if customMessage = ''
self.Message = mlTheFollowingErrorsHaveBeenRaised_
else
self.Message = customMessage
endIf
if self.Interact(self.Scenario.WFErrorFixerModal, Consultation, True) = rValid
endIf
endProc
Create a scenario in your aWFErrorFixer called WFErrorFixerMain:
In the code section of this scenario, the WFErrorFixerMainAgent would be a child of the aUIAgent. The aUIAgent has a method called ChangePos():
function InteractWithUser(ExecMode : tExecMode, IsModal : Boolean) return tResult override
self.ChangePos(4000, 4000, 100, 100)
return inherited self.InteractWithUser(ExecMode, IsModal)
endFunc
I have a content model defined and inside it i have a constraint values with LIST type.
I have a page contains r:propertySheet associated with a node of type "Position" and that type have a property refer to the constraint LIST.
The render of the page is correct, but once i execute a code to setProperties from NodeService, i have the following errors.
A system error happened during the operation: 07230003 Found 1 integrity violations: Invalid property value: Node: workspace://SpacesStore/4c7464b2-2c1b-4346-b3f4-215a3818ac9c Type: {www.ds.alfresco.security.extension.com}position Property: {www.ds.alfresco.security.extension.com}permissions Constraint: 07230002 The value is not an allowed value: [READ SADER, WRITE SADER, READ WARED]
Where My Code is:
if(currentPosition != null && currentPosition.getNodeRef() != null){
Map<String,Object> properties = currentPosition.getProperties();
ArrayList<String> permissions = (ArrayList<String>)properties.get(Constants.SecurityModelQNames.PROP_SEC_POSITION_POSITION_PERMISSIONS);
Map<QName,Serializable> qnameSerializableProperties = NodeUtil.prepareQnameSerializableList(properties);
for(Map.Entry<QName, Serializable> entry : qnameSerializableProperties.entrySet()){
System.out.println(entry.getKey()+","+entry.getValue());
}
getNodeService().setProperties(currentPosition.getNodeRef(), qnameSerializableProperties);
}
What i do to make this code executable?
Simply, i read the values from the page and fill them in a list and again set this list in the node as property.
I define a com object as a dynamic type in c# I am able to call methods quite easily.
However when I try to access a property on the same object I get an invalid cast exception.
The object in question is an array, passed to managed code from JavaScript, and I wish to get the length property of it as an int.
I know I am missing something odd because I am not getting a 'does not contain a definition' exception and I can access the property easily using reflection/InvokeMember.
Why can I not convert the length property of the dynamic type to an int?
For example
This Fails
dynamic com = comObject;
int i = com.length; // RTBE here.
This Works
Type type = comObject.GetType();
int i = (int)type.InvokeMember("length", BindingFlags.GetProperty, null, comObject, null);
* Update *
After a lot of testing I have narrowed this oddness to cases of multi-dimensional arrays.
The com object in question is a parameter passed from a html document to managed code. For all intents and purposes the object sometimes looks like this in JavaScript.
var x = ["a1", "a2", "a3"];
When an array like this comes to managed code I am able to get the length AOK using the type dynamic. (i.e. the first example here that fails actually works). However, if it is a multi-dimensional array such as the following structure in JavaScript.
var y = [["b1", "b2", "b3"], "a2", "a3"];
Then I get an error when trying to access its length property dynamically. Note, I can still access the length via reflection in this case. It seems to me that for some reason the length property does not get correctly mapped when a multidimensional array is used as a dynmaic type...
In my case what I have done to solve(!?) this is add a 'length_' property to the array like so before passing it.
var y = [["b1", "b2", "b3"], "a2", "a3"];
y.length_ = y.length;
Now in managed code I can accesses this property as expected without error. Far from ideal but seems to work...
dynamic com = comObject;
int i = com.length_; // 3!
Further Update
Ok, so it seems that as well as the length property the objects index gets lost to the dynamic type as well. Again it is accessible via reflection though...
Fails
dynamic com = comObject; // js array i.e. var x = [1, 2];
int i = com[0]; // MissingMemberException - Error while invoking [PROPERTYGET, DISPID(0)].
int i = com["0"]; // MissingMemberException - Error while invoking [PROPERTYGET, DISPID(0)].
Works
Type type = comObject.GetType();
int i = (int)type.InvokeMember("0", BindingFlags.GetProperty, null, comObject, null); // 1
In simple terms you can't access the length property of a multi-dimensional array in c# via the type dynamic unless, it seems, you have used the length property in JavaScript first...
The simple test below shows this very clearly. I hope this saves someone else the head scratching I have been having over the last day or so.
[ComVisibleAttribute(true)]
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
webBrowser1.ObjectForScripting = this;
StringBuilder html = new StringBuilder();
html.Append("<script>");
html.Append("var arr1 = [1, 2, 3, 4];");
html.Append("var arr2 = [arr1, 2, 3, 4];");
html.Append("var fn1 = function() { return arr1; };");
html.Append("var fn2 = function() { return arr2; };");
html.Append("var fn3 = function() { alert(arr2.length); }");
html.Append("</script>");
webBrowser1.DocumentText = html.ToString();
webBrowser1.DocumentCompleted += (o, e) =>
{
dynamic arr1 = webBrowser1.Document.InvokeScript("fn1");
int i = arr1.length;
MessageBox.Show(i.ToString()); //4
// If I call fn3 here then the arr2.length *is* available as int i2 below!
////webBrowser1.Document.InvokeScript("fn3"); // 4
dynamic arr2 = webBrowser1.Document.InvokeScript("fn2");
int i2 = arr2.length;
MessageBox.Show(i2.ToString()); // unless fn3 is called you get...
/*
System.MissingMemberException was unhandled by user code
Message=Error while invoking length.
Source=System.Dynamic
StackTrace:
at System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message)
at CallSite.Target(Closure , CallSite , ComObject )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
*/
};
}
}
update
It seems (see comments) that this behaviour is fixed if the WebBrowser control uses version 9 of Internet Explorer (...the control uses the version of IE on the machine). I can only presume that the IE9 'Chakra' JavaScript engine is doing something extra/different to the old js engine in this case.
How do I modify the query below to properly handle the case where the "Summary" element is missing from one of the articles? Now when that happens I get an "Object reference not set to an instance of an object."
var articles = from article in xmlDoc.Descendants("Article")
select new {
articleId = article.Attribute("ID").Value,
heading = article.Element("Heading").Value,
summary = article.Element("Summary").Value,
contents = article.Element("Contents").Value,
cats = from cat in article.Elements("Categories")
select new {
category = cat.Element("Category").Value
}
};
The problem is that article.Element("Summary") returns null if the element is not found, so you get a NullReferenceException when you try to get the Value property.
To solve this, note that XElement also has an explicit conversion to string. This won't throw if the XElement is null - you will just get a null string reference.
So to solve your problem you can change this:
summary = article.Element("Summary").Value,
to this:
summary = (string)article.Element("Summary")