2014年12月

How to disable one specific constraint for a size class?

Say I have a view whose width is 1/2 of the superview in portrait, and 1/3 of the superview in landscape, I thought I could set different multipliers for that constraint, but size class doesn't have this feature.



Then I found a solution in the following post, which says I have to disable and enable constraints for different size classes.



Changing the multiplier of a constraint based on size class



I don't know how to do it. I only find a way of clearing all the constraints. But I don't want to rebuild all the constraints again. I just want change for the one constraint. If I delete that constraint in my current size class, it is also deleted in other size classes. Is there any way I can disable that constraint just for one specific size class?



Answers

Use isActive property.



As documentation says




The active state of the constraint. You can activate or deactivate a
constraint by changing this property. Note that only active
constraints affect the calculated layout. If you try to activate a
constraint whose items have no common ancestor, an exception is
thrown. For newly created constraints, the active property is NO by
default. Activating or deactivating the constraint calls
addConstraint: and removeConstraint: on the view that is the closest
common ancestor of the items managed by this constraint. Use this
property instead of calling addConstraint: or removeConstraint:
directly



Answers

This is how you delete a particular constraint in a particular size class



1.) select the specific size class you need



2.) Click on the view or uielement whose constraints you want to remove/add.



3.) All the constraints of that view or uielement is shown in the right side Attribute Inspector.



4.) Select the particular constraint you want to remove , which sets a blue border on that constraint.



5.) Then press Backspace.



This will delete it for that particular size class only.



This constraint now appears in grey on for that
View Controller.





Why paging query does not work

The main function of this program is to write a page displays the contents of the database and can achieve Pagination



When you first visit the page can display the contents of the database,But when you click on the link below when the page is not able to properly display the contents of the database, the page can display some header



It is a java web code, and what problem with my code?



when first time to visit the java web, it is work, but when i Click Page connection,it only Display header and do not show database.



package com.zigbee.data;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class Data
*/
@WebServlet("/DataInfo")
public class DataInfo extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html; charset=utf-8");
PrintWriter out = response.getWriter();

String Num = request.getParameter("Num");
//out.println("<h1 align=center>基于ZigBee的客车超载管理系统</h1>");
//从数据库中取出数据,并显示
Connection ct = null;
PreparedStatement ps = null;
ResultSet rs = null;

int pageNow = 1; //当前页
int pageSize = 20; //每页显示的记录
int pageCount = 1; //共有多少页
int rowCount = 1; //共有多少记录

//接收提交的pageNow
String spageNow = request.getParameter("pageNow");
if(spageNow != null)
{
pageNow = Integer.parseInt(spageNow);
}

try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
ct = DriverManager.getConnection
("jdbc:sqlserver://localhost:1433; databaseName=zigbee", "sa", "123456");
//算出共多少页
ps = ct.prepareStatement("select count(*) from data where Num="+Num+"");
rs = ps.executeQuery();
rs.next();
rowCount = rs.getInt(1);

pageCount = rowCount%pageSize==0 ? rowCount/pageSize : rowCount/pageSize+1;

ps = ct.prepareStatement("select top "+pageSize+" * from data where Time not in(select top "+(pageNow-1)*pageSize+" Time from data where Num="+Num+" order by Time desc) and Num="+Num+" order by Time desc");
rs = ps.executeQuery();

out.println("<table align=center width=400px border=2 >");
out.println("<tr align=center><th>时间</th><th>车号</th><th>限载人数</th><th>实载人数</th></tr>");

while(rs.next())
{
out.println("<tr><td>"+rs.getString(1)+"</td><td>"+rs.getString(2)+"</td><td>"+rs.getInt(3)+"</td><td>"+rs.getInt(4)+"</td></tr>");
}
out.println("</table>");

for(int i=1; i<=pageCount; i++)
{
out.println("<a href='/ZigBee/DataInfo?pageNow="+i+"'><"+i+"></a>");
}

} catch (Exception e) {
// TODO: handle exception
e.getStackTrace();
}finally{
try {
if(rs != null)
{
rs.close();
}
if(ps != null)
{
ps.close();
}
if(ct != null)
{
ct.close();
}

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
this.doGet(request, response);
}


}



Answers

when you Click Page connection,Num is null





XML to Java Object with JAXB

I have got XML file which I would like to convert to a Java Object.



I have looked at JAXB, but this XML seems far too complex.



Here store has same elements nested into each other. They don't match, and I am unsure of how I would create the annotation class for this.



<?xml version="1.0" encoding="UTF-8"?>
<store id="1" name="main">
<store id="2" name="xx">
<location>here</location>
</store>
<store id="3" name="xx">
<location>here</location>
</store>
<store id="56" name="xx">
<store id="97" name="xx">
<img>store_image.png</img>
<store id="101" name="five">
<img>tore_image.png</img>
<store id="145" name="xx">
<img>tore_image.png</img>
<location>here</location>
</store>
<store id="252" name="xx">
<img>store_image.png</img>
<location>here</location>
</store>
</store>
</store>
</store>
</store>


Answers

can you try



@XmlRootElement(name="store")
@XmlAccessorType(XmlAccessType.FIELD)
public class Store {

// this should take care of nested store elements
@XmlElement(name="store")
private List<Store> stores;

@XmlElement(name="location")
private String location;

@XmlElement(name="img")
private String img;

@XmlAttribute(name="id")
private String id;

@XmlAttribute(name="name")
private String name;

// and include getters and setter
}




Is there an OCaml equivalent of the [<RequireQualifiedAccess>] attribute for DUs in F#?

In F# programs I prefer to use



[<RequireQualifiedAccess>]
type MyType =
| FirstOption of string
| SecondOption of int


so that in code that uses MyType I am forced to write MyType.FirstOption instead of just FirstOption. Is there any way to force this in OCaml?



Answers

You can get a similar effect by defining the type in a module.



$ ocaml
OCaml version 4.02.1

# module MyType = struct
type t = FirstOption of string | SecondOption of int
end ;;
module MyType : sig type t = FirstOption of string | SecondOption of int end
# MyType.FirstOption "abc";;
- : MyType.t = MyType.FirstOption "abc"
# FirstOption "abc";;
Error: Unbound constructor FirstOption
#


If you do it this way, the name of the type (as you can see) is MyType.t.





What is equivalent of boost interprocess named_mutex in STL

I've an application with boost named_mutex implemented to lock multiple modules in a C++ project (Visual Studio). I need to remove all boost dependencies at all costs.



Is there any other way I can implement it? If possible in STL
btw, I'm using C++11



Answers

There is none.



You'll have to drop down to platform specific APIs




https://msdn.microsoft.com/en-us/library/windows/desktop/ms682411(v=vs.85).aspx
Is it possible to use mutex in multiprocessing case on Linux/UNIX ?


Etc.



Answers

You can take a look at Intel's tbb library. It is very fast and created to help with parallel execution.



https://www.threadingbuildingblocks.org/docs/help/reference/synchronization/mutexes.htm





↑このページのトップヘ