How can I "pass" a persistent label in a custom transition animation in iOS8? - uiviewcontroller

I have a custom transition animation between view controllers, and I want a UILabel to be (or appear) the same on both the fromViewController and the toViewController.
I tried the following:
toViewController.nameLabel = fromViewController.nameLabel;
In the context of the code below but got the following error :
[UINavigationController nameLabel]: unrecognized selector sent to
instance
What am I doing wrong?
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
// Grab the from and to view controllers from the context
HC_ExercisePageVC *fromViewController = (HC_ExercisePageVC *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
HC_TimerVC *toViewController = (HC_TimerVC *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
if (self.presenting) {
fromViewController.view.userInteractionEnabled = NO;
[transitionContext.containerView addSubview:toViewController.view];
CGRect startFrame = endFrame;
startFrame.origin.y += 75;
toViewController.movingViews.frame = startFrame;
toViewController.nameLabel = fromViewController.nameLabel;
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
toViewController.movingViews.frame = endFrame;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}
else {
Update: Following the suggestion by #Gavin, I replaced the code with:
// Grab the from and to view controllers from the context
HC_ExercisePageVC *fromViewController = (HC_ExercisePageVC *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UINavigationController *toViewControllerNavigation = (id)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
HC_TimerVC * toViewController = (HC_TimerVC *)toViewControllerNavigation.viewControllers.firstObject;
But when I do that I get error:
-[HC_TimerVC viewControllers]: unrecognized selector sent to instance
I always get hung up on how to handle navcontrollers...

Looks like your toViewController is contained within a UINavigationController, thus it is returning that as the destination.
So you'll need to grab the HC_TimerVC from the navigation controller:
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
// Grab the from and to view controllers from the context
HC_ExercisePageVC *fromViewController = (HC_ExercisePageVC *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UINavigationController *toViewControllerNavigation = (id)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
HC_TimerVC * toViewController = toViewControllerNavigation.viewControllers.firstObject;
....

Related

Xades4j - RuntimeException : "Could not resolve the node to a handle." with custom SignatureAppendingStrategy

I am trying to sign a UBL document and I want to append the signature generated by xades4j within Extensions element tree like this :
<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2">
<ext:UBLExtensions>
<ext:UBLExtension>
<ext:ExtensionURI>urn:oasis:names:specification:ubl:dsig:enveloped:xades</ext:ExtensionURI>
<ext:ExtensionContent>
<sig:UBLDocumentSignatures xmlns:sig="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2" xmlns:sac="urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2" xmlns:sbc="urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2">
<sac:SignatureInformation>
<cbc:ID>urn:oasis:names:specification:ubl:signature:1</cbc:ID>
<sbc:ReferencedSignatureID>
urn:oasis:names:specification:ubl:signature:Invoice
</sbc:ReferencedSignatureID>
*ds:Signature element goes here...*
</sac:SignatureInformation>
</sig:UBLDocumentSignatures>
</sig:UBLDocumentSignatures>
</ext:ExtensionContent>
</ext:UBLExtension>
</ext:UBLExtensions>
rest of Invoice children ...
</Invoice>
Code to generate signature :
org.w3c.dom.Document w3cDoc = ...;
KeyingDataProvider keyingDataProvider = new AppxKeyDataProvider();
SignatureAlgorithms signatureAlgorithms = new
SignatureAlgorithms().withSignatureAlgorithm("ECDSA", XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA256);
XadesSigningProfile profile = new XadesBesSigningProfile(keyingDataProvider).withSignatureAlgorithms(signatureAlgorithms);
XadesSigner signer = profile.newSigner();
DataObjectDesc desc = new DataObjectReference("")
.withTransform(new XPathTransform("not(//ancestor-or-self::ext:UBLExtensions)"))
.withTransform(new XPathTransform("not(//ancestor-or-self::cac:Signature)"))
.withTransform(new XPathTransform("not(//ancestor-or-self::cac:AdditionalDocumentReference[cbc:ID='QR'])"))
.withTransform(new xades4j.algorithms.CanonicalXMLWithoutComments());
XadesSignatureResult result = signer.sign(new SignedDataObjects(desc), w3cDoc.getDocumentElement(),signatureAppendingStrategy);
Custom SignatureAppendingStrategy.append() method implementation
#Override
public void append(Element signatureElement, Node referenceNode) {
Element ublExtensions = w3cDoc.createElementNS("urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2","UBLExtensions");
ublExtensions.setPrefix("ext");
Element ublExtension = w3cDoc.createElementNS("urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2","UBLExtension");
ublExtension.setPrefix("ext");
ublExtensions.appendChild(ublExtension);
Element extensionURL = w3cDoc.createElementNS("urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2","ExtensionURI");
extensionURL.setPrefix("ext");
Node urlValue = w3cDoc.createTextNode("urn:oasis:names:specification:ubl:dsig:enveloped:xades");
extensionURL.appendChild(urlValue);
ublExtension.appendChild(extensionURL);
Element extensionContent = w3cDoc.createElementNS("urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2","ExtensionContent");
extensionContent.setPrefix("ext");
ublExtension.appendChild(extensionContent);
Element ublDocumentSignatures = w3cDoc.createElementNS("urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2","sig:UBLDocumentSignatures");
ublDocumentSignatures.setAttribute("xmlns:sac", "urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2");
ublDocumentSignatures.setAttribute("xmlns:sbc", "urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2");
extensionContent.appendChild(ublDocumentSignatures);
Element signatureInformation = w3cDoc.createElementNS("urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2","SignatureInformation");
signatureInformation.setPrefix("sac");
ublDocumentSignatures.appendChild(signatureInformation);
Element cbcId = w3cDoc.createElementNS("urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2","ID");
cbcId.setPrefix("cbc");
Node idValue = w3cDoc.createTextNode("urn:oasis:names:specification:ubl:signature:1");
cbcId.appendChild(idValue);
signatureInformation.appendChild(cbcId);
signatureInformation.appendChild(signatureElement);
referenceNode.insertBefore(ublExtensions, referenceNode.getFirstChild());
}
Exception :
Exception in thread "main" java.lang.RuntimeException: Could not resolve the node to a handle
at org.apache.xml.dtm.ref.DTMManagerDefault.getDTMHandleFromNode(DTMManagerDefault.java:576)
at org.apache.xpath.XPathContext.getDTMHandleFromNode(XPathContext.java:184)
at org.apache.xpath.XPath.execute(XPath.java:303)
at org.apache.xpath.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:121)
at org.apache.xpath.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:91)
at org.apache.xpath.jaxp.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:176)
at org.apache.xml.security.utils.JDKXPathAPI.evaluate(JDKXPathAPI.java:112)
at org.apache.xml.security.transforms.implementations.TransformXPath$XPathNodeFilter.isNodeInclude(TransformXPath.java:138)
at org.apache.xml.security.c14n.implementations.CanonicalizerBase.isVisible(CanonicalizerBase.java:489)
at org.apache.xml.security.c14n.implementations.CanonicalizerBase.canonicalizeXPathNodeSet(CanonicalizerBase.java:366)
at org.apache.xml.security.c14n.implementations.CanonicalizerBase.engineCanonicalizeXPathNodeSetInternal(CanonicalizerBase.java:302)
at org.apache.xml.security.c14n.implementations.CanonicalizerBase.engineCanonicalize(CanonicalizerBase.java:147)
at org.apache.xml.security.transforms.implementations.TransformC14N.enginePerformTransform(TransformC14N.java:70)
at org.apache.xml.security.transforms.Transform.performTransform(Transform.java:326)
at org.apache.xml.security.transforms.Transforms.performTransforms(Transforms.java:267)
at org.apache.xml.security.signature.Reference.getContentsAfterTransformation(Reference.java:450)
at org.apache.xml.security.signature.Reference.calculateDigest(Reference.java:708)
at org.apache.xml.security.signature.Reference.generateDigestValue(Reference.java:417)
at org.apache.xml.security.signature.Manifest.generateDigestValues(Manifest.java:209)
at org.apache.xml.security.signature.XMLSignature.sign(XMLSignature.java:782)
at xades4j.production.SignerBES.sign(SignerBES.java:270)
at testx.TestXades.main(TestXades.java:276)
Actually the exception occurs while I apply the XPath transform "not(//ancestor-or-self::ext:UBLExtensions)".

How to duplicate slider in HTML (esp8266)

I'm doing something With an ESP8266, and I need some help with the HTML part of it.
I want to duplicate 1 slider:
The code is :
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the on/off buttons
// Feel free to change the background-color and font-size attributes to fit your preferences
client.println("<style>body { text-align: center; font-family: \"Trebuchet MS\", Arial; margin-left:auto; margin-right:auto;}");
client.println(".slider { width: 300px; }</style>");
client.println("<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>");
// Web Page
//client.println("</head><body><h1>ESP32 with Servo</h1>");
client.println("<p>Start Temperature: <span id=\"servoPos\"></span></p>");
client.println("<input type=\"range\" min=\"20\" max=\"30\" class=\"slider\" id=\"servoSlider\" onchange=\"servo(this.value)\" value=\""+valueString+"\"/>");
client.println("<script>var slider = document.getElementById(\"servoSlider\");");
client.println("var servoP = document.getElementById(\"servoPos\"); servoP.innerHTML = slider.value;");
client.println("slider.oninput = function() { slider.value = this.value; servoP.innerHTML = this.value; }");
client.println("$.ajaxSetup({timeout:1000}); function servo(pos) { ");
client.println("$.get(\"/?value=\" + pos + \"&\"); {Connection: close};}</script>");
client.println("</body></html>");
//GET /?value=180& HTTP/1.1
if(header.indexOf("GET /?value=")>=0) {
pos1 = header.indexOf('=');
pos2 = header.indexOf('&');
valueString = header.substring(pos1+1, pos2);
//Rotate the servo
//myservo.write(valueString.toInt());
// Serial.println(valueString);
}
}
}
// Clear the header variable
header = "";
This gives me a slider, but I want another one for controlling a different thing, under a different variable.
Since I don't really understand HTML, I have tried to change some variables and duplicate the code myself, but without success. The slider works, but I get a lot of errors.
Second (independent) slider
client.println("<p>Start Sensor2: <span id=\"servoPos2\"></span></p>");
client.println("<input type=\"range\" min=\"20\" max=\"30\" class=\"slider\" id=\"servoSlider2\" onchange=\"servo2(this.value)\" value=\""+valueString+"\"/>");
client.println("<script>var slider2 = document.getElementById(\"servoSlider2\");");
client.println("var servoP2 = document.getElementById(\"servoPos2\"); servoP2.innerHTML = slider2.value;");
client.println("slider2.oninput = function() { slider2.value = this.value; servoP2.innerHTML = this.value; }");
The function servo(pos) (my guess) in the rest code not shown has either to be
duplicated or ???
to stop guessing and helping you please add the following info:
Source code esp8266 or if it is a standard example the name of the ino file
The type of error- during compilation, on the browser console, on serial port?

kotlin try catch block with bundle.getString

We have intent extras that are passed back to an Activity
The code is written with Kotlin 1.3 and is posted below
We do not understand why the code needs to be in a try catch block
Our question is there a better way to write this code and can someone explain why the code requires a try catch block. We know it could be written with when.
The navigation back to this Activity is accomplished with various intents that do not always put all the values that the bundle gets.
One button uses this code
val intent = Intent(this,MainActivity::class.java)
intent.putExtra("FROM", "NEW")
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
startActivity(intent)
While another button uses this code
holder.ivEdit.setOnClickListener {
//val rowid = friendList.get(position).id
val intent = Intent(context, MainActivity::class.java)
intent.putExtra("FROM", "UPDATE")
intent.putExtra("recordID", items.id)
intent.putExtra("PERSON", items.person)
intent.putExtra("PHONE", items.phone)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(intent)
}
Here is the code that is in the Activity that has the try catch code
The code is inside the onCreate function
try {
val bundle: Bundle = intent.extras
from = bundle.getString("FROM","")
txtPerson = bundle.getString("PERSON","")
txtPhone = bundle.getString("PHONE","")
if(from == "UPDATE") {
showMSG("To CANCEL use back button")
id = bundle.getInt("recordID", 4)
btnAdd.visibility = View.INVISIBLE
btnEdit.visibility = View.VISIBLE
btnViewList.visibility = View.INVISIBLE
etPerson.setText(txtPerson)
etPhone.setText(txtPhone)
}else if (from == "DELETE"){
showMSG("To CANCEL use back button")
btnAdd.visibility = View.INVISIBLE
btnViewList.visibility = View.INVISIBLE
btnEdit.visibility = View.INVISIBLE
btnDelete.visibility = View.VISIBLE
etPerson.setText(txtPerson)
etPhone.setText(txtPhone)
etPerson.isEnabled = false
etPhone.isEnabled = false
}else{
btnViewList.visibility = View.VISIBLE
btnAdd.visibility = View.VISIBLE
btnEdit.visibility = View.INVISIBLE
}
if (id != 0) {
//etPerson.setText(txtPerson)
//etPhone.setText(txtPhone)
}
} catch (ex: Exception) {
}
The guess here is that the Activity with the try catch is also navigated to by another activity that passes no information for the bundle so the bundle gets set to null
intent.extras must not be null so if it is null you need a way to deal with that fact
I do not see a better way around the issue than the try catch block
perhaps someone can offer another solution.

i just want to print several images that fetched from a method named repaint and to all these images seperatly on custom cells of table in ios

// custom delegate that takes value in retrieved data array ::
-(void)repaint:(NSMutableArray *)retrievedData
{
if (retrievedData.count > 0)
{
userObj = [retrievedData objectAtIndex:0];
url_Img1=#"http://kiascenehai.pk/assets/uploads/event-images/50x50-thumb/";
url_Img2=userObj.event_dpURL;
url_Img_FULL = [url_Img1 stringByAppendingPathComponent:url_Img2];
[tableData addObjectsFromArray:retrievedData];
[table reloadData];
}
}
This code is printing a single image several times.
[[cell imageView] setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url_Img_FULL]]]];
It's probably this line, where you always take the first object from the array:
userObj = [retrievedData objectAtIndex:0];
// ^
Use Fast Enumeration instead:
-(void)repaint:(NSMutableArray *)retrievedData
{
for (WhateverType *userObj in retrievedData)
{
url_Img1=#"http://kiascenehai.pk/assets/uploads/event-images/50x50-thumb/";
url_Img2=userObj.event_dpURL;
url_Img_FULL = [url_Img1 stringByAppendingPathComponent:url_Img2];
[tableData addObjectsFromArray:retrievedData];
[table reloadData];
}
}
Note: none of the variables in that method should be an instance variable, other than tableData and table. Also that URL manipulation code looks dodgy, but that's a different story...

Adding attribute to checkbox list at runtime

So I have some code that dynamically creates an ASP.NET form based on an XML input file. I'm trying to add attributes to the controls at run time and I'm having some weird issues with list items.
My Server Side Code looks something like this:
Me.radioButtonList = New RadioButtonList()
Me.dropDownList = New DropDownList()
Me.listControl = Nothing
If controlType = "dropdown" Then
Me.listControl = Me.dropDownList
Else
Me.listControl = Me.radioButtonList
End If
For Each ansElement As Answer In strAnswers
Dim newListItem = New ListItem(ansElement.AnswerText, ansElement.AnswerText)
If ansElement.ActionID IsNot Nothing AndAlso ansElement.ActionID <> "" Then
newListItem.Attributes.Add("actionID", ansElement.ActionID)
End If
Me.listControl.Items.Add(newListItem)
Next
Me.listControl.ID = controlID
Me.Controls.Add(Me.listControl)
The problem is when I run the code and the page is render the attributes are being added to the proceeding span tag of the control not the input item itself. So the rendered HTML ends up looking like this.
<span actionID="1">
<input id="lst_dynamic_MedIllnesses_0" name="ctl00$MainContentPlaceHolder$FormGenerator1$lst_dynamic_MedIllnesses$lst_dynamic_MedIllnesses_0" value="None" type="checkbox">
<label for="lst_dynamic_MedIllnesses_0">None</label>
</span>
What do I have to do to get the actionID attribute to be added to the actual input control and not the span tag?
Thanks!
I suppose you are talking about RadioButtonList. The problem with it is that it uses RadioButton control, and it has 3 attributes properties - Attributes, InputAttributes and LabelAttributes. Each of them is used for specific html element.
The problem with RadioButtonList, is that it uses just Attributes property, and doesn't use InputAttributes. Here is code of RadioButtonList.RenderItem method:
protected virtual void RenderItem(ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
{
if (repeatIndex == 0)
{
this._cachedIsEnabled = this.IsEnabled;
this._cachedRegisterEnabled = this.Page != null && !this.SaveSelectedIndicesViewState;
}
RadioButton controlToRepeat = this.ControlToRepeat;
int index1 = repeatIndex + this._offset;
ListItem listItem = this.Items[index1];
controlToRepeat.Attributes.Clear();
if (listItem.HasAttributes)
{
foreach (string index2 in (IEnumerable) listItem.Attributes.Keys)
controlToRepeat.Attributes[index2] = listItem.Attributes[index2];
}
if (!string.IsNullOrEmpty(controlToRepeat.CssClass))
controlToRepeat.CssClass = "";
ListControl.SetControlToRepeatID((Control) this, (Control) controlToRepeat, index1);
controlToRepeat.Text = listItem.Text;
controlToRepeat.Attributes["value"] = listItem.Value;
controlToRepeat.Checked = listItem.Selected;
controlToRepeat.Enabled = this._cachedIsEnabled && listItem.Enabled;
controlToRepeat.TextAlign = this.TextAlign;
controlToRepeat.RenderControl(writer);
if (!controlToRepeat.Enabled || !this._cachedRegisterEnabled || this.Page == null)
return;
this.Page.RegisterEnabledControl((Control) controlToRepeat);
}
controlToRepeat is that RadioButton, and it specifies only Attributes property and ignores InputAttributes.
I can suggest way to fix it - you can create new class that inherits RadioButtonList, and use it instead of default. Here is code of that class:
public class MyRadioButtonList : RadioButtonList
{
private bool isFirstItem = true;
protected override void RenderItem(ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
{
if (isFirstItem)
{
// this.ControlToRepeat will be created during this first call, and then it will be placed into Controls[0], so we can get it from here and update for each item.
var writerStub = new HtmlTextWriter(new StringWriter());
base.RenderItem(itemType, repeatIndex, repeatInfo, writerStub);
isFirstItem = false;
}
var radioButton = this.Controls[0] as RadioButton;
radioButton.InputAttributes.Clear();
var item = Items[repeatIndex];
foreach (string attribute in item.Attributes.Keys)
{
radioButton.InputAttributes.Add(attribute, item.Attributes[attribute]);
}
// if you want to clear attributes for top element, in that case it's a span, then you need to call
item.Attributes.Clear();
base.RenderItem(itemType, repeatIndex, repeatInfo, writer);
}
}
A bit of description - it has isFirstItem property, as RadioButton control that used by it is created in runtime in the first access, so we need to call RenderItem before we can update InputAttrubutes property. So we call it once and send some stub HtmlTextWriter, so it won't be displayed twice. And then after that we just get this control as Controls[0], and for each ListItem we update InputAttributes values.
PS. Sorry, I didn't use VB.Net so control is written in C#