isEqual
проверяет равенство объекта с другим объектом. Если строки в вашем массиве menuList
все в верхнем регистре, то это нормально. Если они похожи на ваш пример перед кодом, то у вас будут проблемы. Кроме того, если они обе строки NSStrings, вам следует использовать isEqualToString
вместо isEqual
. Вы можете проверить это, выполнив что-то вроде этого:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *arrayValue = [menuList objectAtIndex:indexPath.row];
NSString *myValue = @"LOCATION";
NSLog(@"array value: '%@' my value: '%@'",arrayValue,myValue);
}
Релиз недействителен, поскольку объект находится вне области видимости.
Область действия объектов - это текущая "видимая" база кода для этой переменной. Вот несколько примеров:
- (void)aRandomFunction {
/* here is a variable/object. Its scope is the whole function because it has been
declared directly in the function. All constructs have access to it (within the function) */
NSString *myString = @"My String";
if(YES){
NSLog(@"%@", myString); // myString is visible here because its in scope.
}
}
- (void)anotherRandomFunction {
if(YES){
/* here, because we've declared the variable within the if statement
it's no longer a direct object of the function. Instead its a direct
child of the if statement and is therefore only "visible" within that
if statement */
NSString *myString = @"My String";
NSLog(@"%@", myString); // myString is visible here because its in scope.
}
NSLog(@"%@", myString); // but NOT available here because it is out of scope
}
Таким образом, по сути, область действия переменной - это ее прямая родительская конструкция и все дочерние конструкции ее родителя.
Так что есть два способа сделать ваш пример. Мой любимый это так:
- (void)aFunctionToPushAViewController {
UIViewController *nextPage = NULL;
if(YES){
nextPage = [[CustomViewController alloc] initWithNibName:nil bundle:nil];
}
else {
nextPage = [[ADifferentViewController alloc] initWithNibName:nil bundle:nil];
}
[self.navigationController pushViewController:nextPage animated:YES];
[nextPage release];
}
или ... вы можете просто отпустить его в операторе if ...
- (void)aFunctionToPushAViewController {
if(YES){
CustomViewController *nextPage = [[CustomViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:nextPage animated:YES];
[nextPage release];
}
else {
ADifferentViewController *nextPage = [[ADifferentViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:nextPage animated:YES];
[nextPage release];
}
}