问:
Angular 4 - pushing a new item to an array from an observable
I have a page where I display a list with locations, and clicking on each of them I am displaying assets for that location. I have set up the template like this:

```<code><li
    *ngFor="let location of locations"
    (click)="select(location)"
    droppable
    [dragOverClass]="'drag-target-border'"
    (onDrop)="onItemDrop($event, location)"
    >
      {{ location.name }}
      <ul *ngIf="currentLocation == location && assetsVisible">
        <ng-container *ngIf="currentLocation.assets?.length > 0;else message">
          <li
            *ngFor="let asset of currentLocation.assets"
            class="asset"
            draggable
            [dragData]="asset"
            >
            <p>{{ asset.title }}</p>
            <p>{{ asset.address }}</p>
            <p>{{ asset.value }}</p>
          </li>
        </ng-container>
        <ng-template #message>No assets for {{ location.name }}</ng-template>
      </ul>
  </li>
</code>```

And in the component, I have set the empty assets array, and an empty currentLocation:

```<code>  locations: any[] = [];
  currentLocation: any = {};
  assets: any[] = [];
</code>```

And then in the method select I am fetching the assets like this:

```<code>  select(location:any = {){

    if (this.currentLocation != location || !this.assetsVisible) {
      this.assetsVisible = true;
    }
    else {
      this.assetsVisible = false;
    }

    this.currentAddress = address;

    this.locationService.getAssets(location.Id)
      .subscribe(
        assets => this.assets = assets
      );
  }
</code>```

What I would like to do is to since I am using the drag and drop plugin for Angular I would like to make it possible for user to drag assets from one location to another. And then just temporarily push that asset to an array assets.
I have made a function for that:

```<code>onItemDrop(e: any, location:any = {}) {
   this.assets = [];
   this.assets.push(e.dragData);
   this.select(location);
}
</code>```

So, when a user drags and drops the asset from one location to another, I am emptying the assets array, and pushing the new asset that was dragged to the array.
But, then in the select method I am getting all the assets for that new location that the asset was dropped to, and that rewrites the assets array.
How can I push to the same array those assets, so that I have both the new asset added and the assets of that location that I get from the service endpoint?
I have tried another approach as well, where I was first emptying array assets, and then calling and passing new location and new asset to select method:

```<code>onItemDrop(e: any, location:any = {}) {
    this.assets = [];
    this.select(location, e.dragData);
  }
</code>```

And then, in the select method I have set the asset parameter as optional, and then pushing it there to the assets array after I got all the assets for that location from the service:

```<code>select(location:any = {}, asset?:any = {}) {

    this.locationService.getAssets(location.Id)
      .subscribe(
        assets => this.assets = assets,
        if (asset) {this.assets.push(asset)}
      );
  }
</code>```

But, that didn't work, the asset dropped to new location wasn't displayed in the template. How can I achieve that?

答:
Well in your first approach, you're overwriting your assets array in your subscribe function:

```<code>this.locationService.getAssets(location.Id).subscribe(
    assets => this.assets = assets
);
</code>```

So obviously, the asset you temporarily saved in that array is lost at this point.

Your second approach makes more sense, but you're using subscribe wrong in this example:

```<code>this.locationService.getAssets(location.Id).subscribe(
    assets => this.assets = assets,
    if (asset) {this.assets.push(asset)}
);
</code>```

In this case the if (asset) ... part is passed as the second argument to your subscribe call which is the error callback. You want to do it like this:

```<code>this.locationService.getAssets(location.Id).subscribe( (assets) => {
    this.assets = assets;
    if (asset) {
         this.assets.push(asset)
    }
});
</code>```

Hope it helps.

Update:
I'm not even sure if that if (asset) ... part, the way you implemented it, is even working as error callback. you probably get an error there if that callback is called because a function is expected, not an expression (but as i said, i'm not sure about that).

Body:
I have a page where I display a list with locations, and clicking on each of them I am displaying assets for that location. I have set up the template like this:

      {{ location.name }}

        <ng-container *ngIf="currentLocation.assets?.length > 0;else message">

{{ asset.title }}

{{ asset.address }}

{{ asset.value }}

        </ng-container>
        <ng-template #message>No assets for {{ location.name }}</ng-template>

And in the component, I have set the empty assets array, and an empty currentLocation:

  locations: any[] = [];
  currentLocation: any = {};
  assets: any[] = [];

And then in the method select I am fetching the assets like this:

  select(location:any = {){

    if (this.currentLocation != location || !this.assetsVisible) {
      this.assetsVisible = true;
    }
    else {
      this.assetsVisible = false;
    }

    this.currentAddress = address;

    this.locationService.getAssets(location.Id)
      .subscribe(
        assets => this.assets = assets
      );
  }

What I would like to do is to since I am using the drag and drop plugin for Angular I would like to make it possible for user to drag assets from one location to another. And then just temporarily push that asset to an array assets.
I have made a function for that:

onItemDrop(e: any, location:any = {}) {
   this.assets = [];
   this.assets.push(e.dragData);
   this.select(location);
}

So, when a user drags and drops the asset from one location to another, I am emptying the assets array, and pushing the new asset that was dragged to the array.
But, then in the select method I am getting all the assets for that new location that the asset was dropped to, and that rewrites the assets array.
How can I push to the same array those assets, so that I have both the new asset added and the assets of that location that I get from the service endpoint?
I have tried another approach as well, where I was first emptying array assets, and then calling and passing new location and new asset to select method:

onItemDrop(e: any, location:any = {}) {
    this.assets = [];
    this.select(location, e.dragData);
  }

And then, in the select method I have set the asset parameter as optional, and then pushing it there to the assets array after I got all the assets for that location from the service:

select(location:any = {}, asset?:any = {}) {

    this.locationService.getAssets(location.Id)
      .subscribe(
        assets => this.assets = assets,
        if (asset) {this.assets.push(asset)}
      );
  }

But, that didn't work, the asset dropped to new location wasn't displayed in the template. How can I achieve that?

Body:
Well in your first approach, you're overwriting your assets array in your subscribe function:

this.locationService.getAssets(location.Id).subscribe(
    assets => this.assets = assets
);

So obviously, the asset you temporarily saved in that array is lost at this point.

Your second approach makes more sense, but you're using subscribe wrong in this example:

this.locationService.getAssets(location.Id).subscribe(
    assets => this.assets = assets,
    if (asset) {this.assets.push(asset)}
);

In this case the if (asset) ... part is passed as the second argument to your subscribe call which is the error callback. You want to do it like this:

this.locationService.getAssets(location.Id).subscribe( (assets) => {
    this.assets = assets;
    if (asset) {
         this.assets.push(asset)
    }
});

Hope it helps.

Update:
I'm not even sure if that if (asset) ... part, the way you implemented it, is even working as error callback. you probably get an error there if that callback is called because a function is expected, not an expression (but as i said, i'm not sure about that).


来源: stackexchange

问:
Efficiently detect if a device will play silent videos that have the autoplay attribute
With Chrome 53 and iOS 10 both out now, there are now Android and iOS devices that are capable of automatically playing videos that are silent and have the autoplay attribute. I'd like to know how to detect this with JavaScript.

For Chrome 53, the <video> must have the autoplay and muted attributes (yes, the muted attribute is required even if the video file doesn't have any audio tracks).

For iOS 10, the <video> must have the autoplay attribute and, for non-iPad iOS 10 devices, the playsinline attribute too (yes, it must be playsinline; webkit-playsinline won't work).

So a <video> will automatically play in both Chrome 53 and iOS 10 (including non-iPad iOS 10 devices) if it has all three attributes: autoplay, muted, and playsinline.

If I were just interested in detecting this on iOS 10 devices, the code would be quite simple. I'm using jQuery, but this could easily be converted into vanilla JavaScript:

```<code>var muted_videos_autoplay = false;

$('<video playsinline>').on('play', function() {
  muted_videos_autoplay = true;
})[0].play();

setTimeout(function() {
  alert('muted_videos_autoplay: ' + muted_videos_autoplay);
}, 300);
</code>```

But on Chrome 53, the only way I've found to do it is quite complicated:

```<code>var muted_videos_autoplay = false;

$('<video autoplay muted style="position: fixed; top: 0; opacity: 0; pointer-events: none;" src="data:video/mp4;base64, [encoded data, 5004 characters]">').on('play', function() {
  muted_videos_autoplay = true;
  $(this).remove();
}).appendTo('body');

setTimeout(function() {
  alert('muted_videos_autoplay: ' + muted_videos_autoplay);
}, 300);
</code>```

For the record, I got the video source from here.

I could make the Chrome 53 code work for all iOS 10 devices too simply by adding the playsinline attribute onto the <video> that gets appended to the . But I'd like to find a more efficient way to detect this behavior, if possible. Does anybody know of one?

答:
You can detect video autoplay support by checking if the paused status of a video element changes after it programmatically plays. This alone can return false negatives in some mobile browsers, so a Promise check should be added in order to cover these.

This method works in all major browsers (desktop and mobile), except for Android <= 4.0 and Windows Phone, where it returns a false negative.

Here is the detect function:

var supports_video_autoplay = function(callback) {

  if (typeof callback !== "function") return false;

  var v = document.createElement("video");
  v.paused = true;
  var p = "play" in v && v.play();

  callback(!v.paused || ("Promise" in window && p instanceof Promise));

};
```

<p>Usage:</p>

<pre class="lang-js prettyprint-override"><code>supports_video_autoplay(function(supported) {
  if (supported) {
    // video autoplay supported!
  } else {
    // no video autoplay support :(
  }
});
</code>```

Live test: https://codepen.io/paulorely/pen/QveEGy

ContentLicense: CC BY-SA 3.0

Body:
With Chrome 53 and iOS 10 both out now, there are now Android and iOS devices that are capable of automatically playing videos that are silent and have the autoplay attribute. I'd like to know how to detect this with JavaScript.

For Chrome 53, the <video> must have the autoplay and muted attributes (yes, the muted attribute is required even if the video file doesn't have any audio tracks).

For iOS 10, the <video> must have the autoplay attribute and, for non-iPad iOS 10 devices, the playsinline attribute too (yes, it must be playsinline; webkit-playsinline won't work).

So a <video> will automatically play in both Chrome 53 and iOS 10 (including non-iPad iOS 10 devices) if it has all three attributes: autoplay, muted, and playsinline.

If I were just interested in detecting this on iOS 10 devices, the code would be quite simple. I'm using jQuery, but this could easily be converted into vanilla JavaScript:

var muted_videos_autoplay = false;

$('<video playsinline>').on('play', function() {
  muted_videos_autoplay = true;
})[0].play();

setTimeout(function() {
  alert('muted_videos_autoplay: ' + muted_videos_autoplay);
}, 300);

But on Chrome 53, the only way I've found to do it is quite complicated:

var muted_videos_autoplay = false;

$('<video autoplay muted style="position: fixed; top: 0; opacity: 0; pointer-events: none;" src="data:video/mp4;base64, [encoded data, 5004 characters]">').on('play', function() {
  muted_videos_autoplay = true;
  $(this).remove();
}).appendTo('body');

setTimeout(function() {
  alert('muted_videos_autoplay: ' + muted_videos_autoplay);
}, 300);

For the record, I got the video source from here.

I could make the Chrome 53 code work for all iOS 10 devices too simply by adding the playsinline attribute onto the <video> that gets appended to the . But I'd like to find a more efficient way to detect this behavior, if possible. Does anybody know of one?

Body:
You can detect video autoplay support by checking if the paused status of a video element changes after it programmatically plays. This alone can return false negatives in some mobile browsers, so a Promise check should be added in order to cover these.

This method works in all major browsers (desktop and mobile), except for Android <= 4.0 and Windows Phone, where it returns a false negative.

Here is the detect function:

var supports_video_autoplay = function(callback) {

  if (typeof callback !== "function") return false;

  var v = document.createElement("video");
  v.paused = true;
  var p = "play" in v && v.play();

  callback(!v.paused || ("Promise" in window && p instanceof Promise));

};

Usage:

supports_video_autoplay(function(supported) {
  if (supported) {
    // video autoplay supported!
  } else {
    // no video autoplay support :(
  }
});

Live test: https://codepen.io/paulorely/pen/QveEGy


问:
How do I shutdown JBoss Wildfly when I can't access the CLI tool?
I"m using Wildfly 10.0.0.CR2 with Java 8.  I have Wildfly listening for http connections on port 8080 and in the past have used this command to shut down the server ...

```<code>./jboss-cli.sh --connect command=:shutdown
</code>```

HOwever, occassionally, I'm not able to access this tool, even though the server is still running.  Note the interaction below on my Mac ...

```<code>Daves-MacBook-Pro-2:bin davea$ ./jboss-cli.sh --connect command=:shutdown
Failed to connect to the controller: The controller is not available at localhost:9990: java.net.ConnectException: WFLYPRT0023: Could not connect to http-remoting://localhost:9990. The connection timed out: WFLYPRT0023: Could not connect to http-remoting://localhost:9990. The connection timed out
Daves-MacBook-Pro-2:bin davea$ telnet localhost 8080
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
</code>```

My question is, what is a foolproof way to shutdown the JBoss server?  Note I would prefer a method that does not rely on the CLI tool.

答:
To stop Wildfly:</p>

```<code>$ ./jboss-cli.sh --connect command=:shutdown
</code>```

Body:
I"m using Wildfly 10.0.0.CR2 with Java 8.  I have Wildfly listening for http connections on port 8080 and in the past have used this command to shut down the server ...

./jboss-cli.sh --connect command=:shutdown

HOwever, occassionally, I'm not able to access this tool, even though the server is still running.  Note the interaction below on my Mac ...

Daves-MacBook-Pro-2:bin davea$ ./jboss-cli.sh --connect command=:shutdown
Failed to connect to the controller: The controller is not available at localhost:9990: java.net.ConnectException: WFLYPRT0023: Could not connect to http-remoting://localhost:9990. The connection timed out: WFLYPRT0023: Could not connect to http-remoting://localhost:9990. The connection timed out
Daves-MacBook-Pro-2:bin davea$ telnet localhost 8080
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

My question is, what is a foolproof way to shutdown the JBoss server?  Note I would prefer a method that does not rely on the CLI tool.

Body:
To stop Wildfly:

$ ./jboss-cli.sh --connect command=:shutdown


问:
.Net Inheritance - Automatic dependency referencing behavior issue
I've come across a strange issue that I've just now noticed.

If you have a solution with 3 projects

** NOTE Edited after discussion **

Project LibA - Has a ClassA

```<code>namespace LibA
{
    public class ClassA
    {
        public override string ToString()
        {
            return "The logic in class A!";
        }
    }
}
</code>```

Project LibB - Has a ClassB

```<code>using LibA;

namespace LibB
{
    public class ClassB
    {
        public ClassA a;

        public ClassB()
        {
            a = new ClassA();
        }

        public object Foo()
        {
            return a;
        }
    }
}
</code>```

Project LibC - Has a ClassC

```<code>using LibB;

namespace LibC
{
    public class ClassC
    {
        public ClassB b;

        public ClassC()
        {
            b = new ClassB();
        }

        public object Foo()
        {
            return b.Foo();
        }
    }
}
</code>```

Finally a test driver

```<code>using System;
using LibC;

namespace Shell
{
    class Program
    {
        static void Main(string[] args)
        {
            ClassC c = new ClassC();
            Console.WriteLine(c.Foo());
        }
    }
}
</code>```

Now if you compile this, everything will work perfectly. If you examine the contents of LibC's binary folder, you'll see that it automatically rolled through the chain of dependencies to determine that it needed to pull in LibA and LibB

However, if you alter ClassB to inherit from class A
such as

```<code>using LibA;

namespace LibB
{
    public class ClassB : ClassA
    {
        ClassA a;
    }
}
</code>```

attempt to compile, you'll get the error

Error 2 The type 'LibA.ClassA' is defined in an assembly that is not referenced. You must add a reference to assembly 'LibA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

** Original Question **

Does anyone know why (whether it is msbuild or visual studio) it is smart enough to reference LibA when ClassA a member of ClassB, but it isn't smart enough to reference LibA when ClassA is the base class of ClassB?

I know it's nitpicky, but I would really appreciate some consistent behavior

** Amended Question with these observed tests **

I'm hearing what some define as "direct" or "indirect" references. However, direct is clearly not just the visibility scoping, it seems to be inheritance and actual usage of a type.

Without inheritance, the test driver is smart enough to resolve and automatically reference LibA, LibB and LibC.

There is a public member ClassA visible in ClassB and yet that alone doesn't produce the compilation/linking error.

The debugger definitely resolves ClassA from the test driver, so it clearly loaded the correct assembly.

So with all that in mind. I get the whole "direct" and "indirect" stuff now.

The thing that is still not clicking to me why the linker/compiler/IDE doesn't at least try to automatically reference the dependencies of a referenced library in an "direct" scenario? It's clearly smart enough to know the dependencies are there and reference them in an "indirect" scenario.

答:
I know it's nitpicky, but I would
  really appreciate some consistent
  behavior

It is consistant. You must reference any type that you use directly. Indirect references are resolved transparently.

ContentLicense: CC BY-SA 2.5

Body:
I've come across a strange issue that I've just now noticed.

If you have a solution with 3 projects

** NOTE Edited after discussion **

Project LibA - Has a ClassA

namespace LibA
{
    public class ClassA
    {
        public override string ToString()
        {
            return "The logic in class A!";
        }
    }
}

Project LibB - Has a ClassB

using LibA;

namespace LibB
{
    public class ClassB
    {
        public ClassA a;

        public ClassB()
        {
            a = new ClassA();
        }

        public object Foo()
        {
            return a;
        }
    }
}

Project LibC - Has a ClassC

using LibB;

namespace LibC
{
    public class ClassC
    {
        public ClassB b;

        public ClassC()
        {
            b = new ClassB();
        }

        public object Foo()
        {
            return b.Foo();
        }
    }
}

Finally a test driver

using System;
using LibC;

namespace Shell
{
    class Program
    {
        static void Main(string[] args)
        {
            ClassC c = new ClassC();
            Console.WriteLine(c.Foo());
        }
    }
}

Now if you compile this, everything will work perfectly. If you examine the contents of LibC's binary folder, you'll see that it automatically rolled through the chain of dependencies to determine that it needed to pull in LibA and LibB

However, if you alter ClassB to inherit from class A
such as

using LibA;

namespace LibB
{
    public class ClassB : ClassA
    {
        ClassA a;
    }
}

attempt to compile, you'll get the error

Error 2 The type 'LibA.ClassA' is defined in an assembly that is not referenced. You must add a reference to assembly 'LibA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

** Original Question **

Does anyone know why (whether it is msbuild or visual studio) it is smart enough to reference LibA when ClassA a member of ClassB, but it isn't smart enough to reference LibA when ClassA is the base class of ClassB?

I know it's nitpicky, but I would really appreciate some consistent behavior

** Amended Question with these observed tests **

I'm hearing what some define as "direct" or "indirect" references. However, direct is clearly not just the visibility scoping, it seems to be inheritance and actual usage of a type.

Without inheritance, the test driver is smart enough to resolve and automatically reference LibA, LibB and LibC.

There is a public member ClassA visible in ClassB and yet that alone doesn't produce the compilation/linking error.

The debugger definitely resolves ClassA from the test driver, so it clearly loaded the correct assembly.

So with all that in mind. I get the whole "direct" and "indirect" stuff now.

The thing that is still not clicking to me why the linker/compiler/IDE doesn't at least try to automatically reference the dependencies of a referenced library in an "direct" scenario? It's clearly smart enough to know the dependencies are there and reference them in an "indirect" scenario.


问:
JSON to textView?
I have my app get JSON data from a link, but I need to get status from the JSON.

Status > Code and Msg.

Here is what I have working:

Screenshot:

I need to have it output >

Code : success (or fail, whatever the json says)

Msg : Licence updated.. (Or whatever the JSON spits out)

Any help would be nice or pointing me in the direction, thanks.

Some of my code:

```<code>public class doit extends AsyncTask<Void,Void,Void>{
String words;

        public doit() throws JSONException {
        }

        @Override
        protected Void doInBackground(Void... voids) {

            try {
                WebView wv = (WebView) findViewById(R.id.webview);
                EditText messages = (EditText) findViewById(R.id.messages);
                Document doc = Jsoup.connect("https://api.deepbot.tv/web/apply/namerefresh.php?s=" + messages.getText().toString()).get();

                words=doc.text();

            }catch(Exception e){e.printStackTrace();}

            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);
            texx.setText(words);

        }
</code>```

答:
Blockquote

```<code>JSONObject jObj = arr.getJSONObject(words);
String date = jObj.getString("msg");
</code>```

Blockquote

Title: JSON to textView?

Body:
I have my app get JSON data from a link, but I need to get status from the JSON.

Status > Code and Msg.

Here is what I have working:

Screenshot:

I need to have it output >

Code : success (or fail, whatever the json says)

Msg : Licence updated.. (Or whatever the JSON spits out)

Any help would be nice or pointing me in the direction, thanks.

Some of my code:

public class doit extends AsyncTask<Void,Void,Void>{
String words;

        public doit() throws JSONException {
        }

        @Override
        protected Void doInBackground(Void... voids) {

            try {
                WebView wv = (WebView) findViewById(R.id.webview);
                EditText messages = (EditText) findViewById(R.id.messages);
                Document doc = Jsoup.connect("https://api.deepbot.tv/web/apply/namerefresh.php?s=" + messages.getText().toString()).get();

                words=doc.text();

            }catch(Exception e){e.printStackTrace();}

            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);
            texx.setText(words);

        }

Body:
Blockquote

JSONObject jObj = arr.getJSONObject(words);
String date = jObj.getString("msg");

Blockquote


问:
DOM specified Property return true
Someone told me if the attribute not defined, the specified value will return false. xms attribute did not have definition, but specified return true. What situation does specified return false?</p>

```<code><!DOCTYPE html>
<html>
<body>

<p>Click the button find out if the button has an onclick attribute specified.</p>

<button onclick="myFunction()" class="" xms >Try it</button>

<p id="demo"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<script>
function myFunction() {
    var btn = document.getElementsByTagName("BUTTON")[0];
    var x = btn.getAttributeNode("onclick").specified;
    document.getElementById("demo").innerHTML = x;

        var y = btn.getAttributeNode("class").specified;
    document.getElementById("demo2").innerHTML = y;

        var z = btn.getAttributeNode("xms").specified;
    document.getElementById("demo3").innerHTML = z;

}
</script>

</body>
</html>
</code>```

答:
Since xms is present in the tag then its considered as specified.

In fact, I think that DOM attributes in tags without values are by default considered boolean attributes with value of true, like the hidden or checked attribute.

Title: DOM specified Property return true

Body:
Someone told me if the attribute not defined, the specified value will return false. xms attribute did not have definition, but specified return true. What situation does specified return false?

<!DOCTYPE html>

Click the button find out if the button has an onclick attribute specified.

<button onclick="myFunction()" class="" xms >Try it</button>


问:
How to get value of all inputs not type hidden
I want to clear value of all inputs but except input type hidden which contains some value I want to submit on server.

What is the best way to select all form fields in a form but ignore hidden fields in the selection?

答:
Select all input fields which are not hidden.</p>

```<code>jQuery('input[type!=hidden]').val('');
</code>```

Body:
Select all input fields which are not hidden.

jQuery('input[type!=hidden]').val('');


问:
Wrong TableView Height with 64bit Devices
I have a really strange Problem. With 64bit Devices i always geht a wrong cell height. On 32bit Devices it looks correct like this:

On Devices with 64bit Architecture, it looks like this:

This is my function, and YES i changed it from float to CGFloat after 64bit Devices got released....

```<code>-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
GFBlockTableRowItem* row = [self.blockTable.tableRows objectAtIndex:indexPath.row];

CGFloat maxHeight = 0.0f;

for (NSUInteger i=0; i<row.tableColumns.count; ++i) {
    NSString* widthValue = [self.blockTable.tableColWidths objectAtIndex:i];

    CGFloat percentage = widthValue.integerValue/100.0f;
    NSString* string = [row.tableColumns objectAtIndex:i];

    CGSize constraint = CGSizeMake(self.frame.size.width*percentage, FLT_MAX);
    CGSize size = calculateSizeWithInsets(string, self.defaultCellFont, constraint, GTDefaultTableEdgeInsets);

    maxHeight = MAX(size.height, maxHeight);
}

LogDebug(@"height %li: %.3f", (long)indexPath.row, maxHeight);
return maxHeight;
}
</code>```

EDIT 1:

```<code>typedef NS_ENUM(NSInteger, GTVerticalTextAlignment) {
GTVerticalTextAlignmentTop,
GTVerticalTextAlignmentCenter,
GTVerticalTextAlignmentBottom
};

/**top, left, bottom, right*/
static UIEdgeInsets GTDefaultTableEdgeInsets = {0.0f, 0.0f, 0.0f, 0.0f};
static UIEdgeInsets GTDefaultTextViewEdgeInsets = {8.0f, 4.0f, 8.0f, 4.0f};

CGSize calculateSizeWithInsets(NSString *text,UIFont *font, CGSize size, UIEdgeInsets insets) {
//  GT_SIZE_CONSTRAINT_NONE
CGSize constraint = size;
UIEdgeInsets effective = UIEdgeInsetsMake((insets.top + GTDefaultTextViewEdgeInsets.top),
                                          (GTDefaultTextViewEdgeInsets.left + insets.left),
                                          (insets.bottom + GTDefaultTextViewEdgeInsets.bottom),
                                          (GTDefaultTextViewEdgeInsets.right + insets.right));

if (constraint.width != GT_SIZE_CONSTRAINT_NONE) {
    constraint.width = constraint.width - (effective.left + effective.right);
}

if (constraint.height != GT_SIZE_CONSTRAINT_NONE) {
    constraint.height = constraint.height - (effective.top + effective.bottom);
}

CGSize textSize = calculateSize(text, font, constraint);

if (constraint.width == GT_SIZE_CONSTRAINT_NONE) {
    textSize.width += effective.left + effective.right;
}

if (constraint.height == GT_SIZE_CONSTRAINT_NONE) {
    textSize.height += effective.top + effective.bottom;
}

return textSize;
}
</code>```

答:
In my case below method was being used

```<code>- (float)tableView: (UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *)indexPath
</code>```

instead of this updated method.

```<code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
</code>```

In 64 bit architecture float should be replaced with CGFloat.

Body:
I have a really strange Problem. With 64bit Devices i always geht a wrong cell height. On 32bit Devices it looks correct like this:

On Devices with 64bit Architecture, it looks like this:

This is my function, and YES i changed it from float to CGFloat after 64bit Devices got released....

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
GFBlockTableRowItem* row = [self.blockTable.tableRows objectAtIndex:indexPath.row];

CGFloat maxHeight = 0.0f;

for (NSUInteger i=0; i<row.tableColumns.count; ++i) {
    NSString* widthValue = [self.blockTable.tableColWidths objectAtIndex:i];

    CGFloat percentage = widthValue.integerValue/100.0f;
    NSString* string = [row.tableColumns objectAtIndex:i];

    CGSize constraint = CGSizeMake(self.frame.size.width*percentage, FLT_MAX);
    CGSize size = calculateSizeWithInsets(string, self.defaultCellFont, constraint, GTDefaultTableEdgeInsets);

    maxHeight = MAX(size.height, maxHeight);
}

LogDebug(@"height %li: %.3f", (long)indexPath.row, maxHeight);
return maxHeight;
}

EDIT 1:

typedef NS_ENUM(NSInteger, GTVerticalTextAlignment) {
GTVerticalTextAlignmentTop,
GTVerticalTextAlignmentCenter,
GTVerticalTextAlignmentBottom
};

/**top, left, bottom, right*/
static UIEdgeInsets GTDefaultTableEdgeInsets = {0.0f, 0.0f, 0.0f, 0.0f};
static UIEdgeInsets GTDefaultTextViewEdgeInsets = {8.0f, 4.0f, 8.0f, 4.0f};

CGSize calculateSizeWithInsets(NSString *text,UIFont *font, CGSize size, UIEdgeInsets insets) {
//  GT_SIZE_CONSTRAINT_NONE
CGSize constraint = size;
UIEdgeInsets effective = UIEdgeInsetsMake((insets.top + GTDefaultTextViewEdgeInsets.top),
                                          (GTDefaultTextViewEdgeInsets.left + insets.left),
                                          (insets.bottom + GTDefaultTextViewEdgeInsets.bottom),
                                          (GTDefaultTextViewEdgeInsets.right + insets.right));

if (constraint.width != GT_SIZE_CONSTRAINT_NONE) {
    constraint.width = constraint.width - (effective.left + effective.right);
}

if (constraint.height != GT_SIZE_CONSTRAINT_NONE) {
    constraint.height = constraint.height - (effective.top + effective.bottom);
}

CGSize textSize = calculateSize(text, font, constraint);

if (constraint.width == GT_SIZE_CONSTRAINT_NONE) {
    textSize.width += effective.left + effective.right;
}

if (constraint.height == GT_SIZE_CONSTRAINT_NONE) {
    textSize.height += effective.top + effective.bottom;
}

return textSize;
}

Body:
In my case below method was being used

- (float)tableView: (UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *)indexPath

instead of this updated method.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

In 64 bit architecture float should be replaced with CGFloat.


问:
How could I check if string is only match into an other string
I'm actually a beginner into web developpment.

I have a problem with my actual condition.

Exemple :

```<code>$rooms = 10;
</code>```

In my code, I check if $rooms is equal to 1,0 or 10 so :

```<code>if(strpos($rooms, '1')){echo 1;}
if(strpos($rooms, '0')){echo 0};
if(strpos($rooms, '10')){echo 10;}
</code>```

My result :

```<code>1
0
10
</code>```

My condition match for 1, 0 and 10, where I only need to match the number 10

How can I only pass into my third condition ?

Thx

答:
Use something like this

```<code>$rooms === ('your number') ? echo '(your number)' : echo '(else)';
</code>```

change 'your number' with any number u like.
change echo '(else)' with anything u want if the condition is not met
or leave just '' after a colon for nothing to happen

Body:
I'm actually a beginner into web developpment.

I have a problem with my actual condition.

Exemple :

$rooms = 10;

In my code, I check if $rooms is equal to 1,0 or 10 so :

if(strpos($rooms, '1')){echo 1;}
if(strpos($rooms, '0')){echo 0};
if(strpos($rooms, '10')){echo 10;}

My result :

1
0
10

My condition match for 1, 0 and 10, where I only need to match the number 10

How can I only pass into my third condition ?

Thx

Body:
Use something like this

$rooms === ('your number') ? echo '(your number)' : echo '(else)';

change 'your number' with any number u like.
change echo '(else)' with anything u want if the condition is not met
or leave just '' after a colon for nothing to happen