I cannot save the selected item from the array with a string value. Any idea what’s wrong?
Its my code of compare:
if(self.detailItem){
[WebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[self.detailItem description] ofType:@"html"]isDirectory:NO]]];
NSString *value = (NSString *)self.detailItem;
NSString *value1 = (NSString *)@"DecideVectorVPiramidi";
value=[NSString stringWithFormat:@"%@", value];
value1=[NSString stringWithFormat:@"%@", value1];
if (value == value1) {
WebView.scalesPageToFit=YES;
}
This is the array code:
case 1:
switch (self.nomberInSection) {
case 0:
self.detailViewController.detailItem =[NSString stringWithFormat:@"%@", [DecideOfZakusPath objectAtIndex:indexPath.row]];
break;
}
break;
Type of detailItem is id.
For errors, I checked
You need to use
isEqualToString. The==operator will compare by reference only.This means you have to do
Your two strings will be pointers to two different memory locations, and the
==will compare those two memory locations, and consequently evaluate toNO. TheisEqualToString, orisEqual, is the method to use for doing a string comparison using the string equality rules (ie. if the two strings contains the same characters, they are considered equal).This can be a bit counter-intuitive. In Objective-C, operator overloading is not possible. In many other languages, the operators can be overloaded so that a value comparison for built in and custom classes can be done using the equality operator.