Thursday, 3 October 2013

UILabel with multiple lines and Auto Resizing Masks (UIViewAutoresizingMask)

UILabel with multiple lines and Auto Resizing Masks (UIViewAutoresizingMask)

I have a problem with UILabels that contain text that is spread on
multiple lines. It's nested into a fullscreen UIView that has autoresizing
mask as well:
view.autoresizingMask =
UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
I'd like to add autoresizingMask on the label
label.autoresizingMask =
UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
But the problem is, this doesn't work as I'd like it to work. If I do
this, after rotating the screen (which changes size of the view) then the
label has smaller height and some of the text is cut off. (It doesn't
display the whole text). If I don't add UIViewAutoresizingFlexibleHeight,
then the label after rotation has big gaps above and under text (And I
don't want that). I tried adding also
UIViewAutoresizingFlexibleBottomMargin, but this doesn't help, as still
not whole text is displayed. I really don't know how to make this work,
I'm almost convinced autoresizing masks don't work with multiline
uilabels... Any idea on this would be appreciated. Thanks :)

Wednesday, 2 October 2013

Unclear Compile-time Java Exception

Unclear Compile-time Java Exception

I'm running into peculiar behavior in terms of compile time exceptions
with the following code (I'm using JDK7):
public class classA { public void foo( List<Object> o ){} }
public classB<T>{ public void bar( List<Object> o ){} }
We consider the the following test object
List<String> o = new ArrayList<String>();
There is no way to get java to compile by passing o as a parameter to the
method foo of class classA, and as far as I can figure, there shouldn't
be.
Now say we're in the main method of classB and try to just call bar
without instantiating an instance of classB to call it on. I might expect
to get a non-static method can't be called from static context compilation
error like I would if I tried to pull that in classA, but instead I get a
conversion invocation error. That, makes sense - the types don't line up.
However if I try call bar from a nonstatic context, as in
ClassB b = new classB();
b.bar( o );
Java seems to forgive me for not lining up the types and runs the code no
problem. I haven't done anything to fix the issue of typcasting, so why
does Java let this code execute, where it wouldn't with classA?

How to map two String[] to each other

How to map two String[] to each other

I'm developing an Android app. I'm mapping two arrays to each other with a
HashMap. I change these arrays into String[]'s, and map them together. It
should return values, but it returns null. I'm not sure where I'm going
wrong. I've searched online, but I haven't found anything useful. My code
is below:
Part of StationList.java
Spinner2.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
String selectedValue =
arg0.getItemAtPosition(arg2).toString();
String[] Yellow_ID =
getResources().getStringArray(R.array.Yellow_ID);
String[] Yellow_Li =
getResources().getStringArray(R.array.Yellow_Line);
Map<String[], String[]> myMap = new HashMap<String[],
String[]>();
myMap.put(Yellow_Li, Yellow_ID);
String[] value = myMap.get(selectedValue);
tv12.setText(String.valueOf (value));
}
Value returns null in the TextView. I think this is due to the values not
mapping to each other. I would appreciate any help you could give me.

How to separate a string into 4 separate arrays

How to separate a string into 4 separate arrays

Ok so to start off i'm a beginner to objective c. I got a project where
i'm suppose to take a csv file and read it into the system into 4 separate
arrays, (City, Country, Latitude, and Longitude. My first question is can
you use the old school string instead of NNString. I did the same project
in c++ and this is what i got.
`ifstream file("worldcities.csv");
getline(file, temporay);
//inputs the file into 4 arrays for each catergories
for (i=0;getline(file,(cities[i]),',');i++)
{
getline(file, countries[i], ',');
getline(file, latitude[i], ',') ;
getline(file, longitude[i]); }'
How can i get the same outcome in Objective c? I tried fgets instead of
getline but i'm still not familiar with it so thats why i come to you
guys. I really do appreciate the help

#EANF#

#EANF#

Can anyone explain me how to connect Java with MySQL?
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
Connection conn = null;
...
try {
conn =
DriverManager.getConnection("jdbc:mysql://localhost/test?" +
"user=monty&password=greatsqldb");
}
catch (SQLException ex)
{
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
This is how i made it but mine is windows authintication and not sql
server authentication. So how to complete the connection with windows
authentication??

Tuesday, 1 October 2013

Why does sizeToFit not work when trying to vertically align my UILabel? It just stays in the center

Why does sizeToFit not work when trying to vertically align my UILabel? It
just stays in the center

I was reading this post for advice on how to vertically align text within
a UILabel, and the top comment seemed to present a great solution.
I have my UILabel, and I set number of lines to 0. Then in viewDidLoad for
the View Controller it's a part of, I called sizeToFit on it, but it still
only occupies the middle.
It looks like this in Interface Builder:

And looks the exact same when I run it, the text is still really far away
from the navigation bar when I'd prefer it to be very close, preferably at
the top of that outline box.
What am I doing wrong?

CORS Options response working in IISExpress but not IIS7.5

CORS Options response working in IISExpress but not IIS7.5

I'm trying to get a CORS request to work however I've been running into
problems when running it on a deployed server
I'm using thinktecture identity model to set up my CORS which works
beautifully when running on a local instance of IIS-express but fails on a
proper IIS 7.5 version of the site.



This is the local version and works perfectly
OPTIONS http://local.api.mysite.org:57339/api/search HTTP/1.1
Host: local.api.mysite.org:57339
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: http://local.mysite.org:62747
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/29.0.1547.76 Safari/537.36
Access-Control-Request-Headers: accept, origin, content-type
Accept: */*
Referer: http://local.mysite.org:62747/search
Accept-Encoding
: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
=======
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Server: Microsoft-IIS/8.0
Access-Control-Allow-Origin: http://local.mysite.org:62747
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: accept,origin,content-type
X-AspNet-Version: 4.0.30319
X-SourceFiles:
=?UTF-8?B?QzpcR2l0XGxpdmVzLWRldmVsb3BcQnJpZ2h0U29saWQuTGl2ZXMuV2ViQXBpXGFwaVxzZWFyY2g=?=
X-Powered-By: ASP.NET
Date: Tue, 01 Oct 2013 21:28:06 GMT
Content-Length: 0



This is the deployed version and fails
OPTIONS http://betatest.api.mysite.org/api/search HTTP/1.1
Host: betatest.api.mysite.org
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: http://betatest.mysite.org
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/29.0.1547.76 Safari/537.36
Access-Control-Request-Headers: accept, origin, content-type
Accept: */*
Referer: http://betatest.mysite.org/search
Accept-Encoding
: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
=======
HTTP/1.1 200 OK
Allow: OPTIONS, TRACE, GET, HEAD, POST
Server: Microsoft-IIS/7.5
Public: OPTIONS, TRACE, GET, HEAD, POST
X-Powered-By: ASP.NET
Date: Tue, 01 Oct 2013 21:31:24 GMT
Content-Length: 0



The GETS work fine on the deployed instance but not the POSTS.
It appears like the OPTIONS preflight response is different between
IISExpress and IIS7.5
I've tried cleaning the cache but that's not made a difference.