gpt4 book ai didi

iphone - 为什么我的if语句不触发?

转载 作者:行者123 更新时间:2023-12-03 08:13:01 25 4
gpt4 key购买 nike

我有以下Objective-C函数

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{


NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];

NSString *key = [keys objectAtIndex:section];
NSArray *nameSection = [mysearchdata objectForKey:key];

static NSString *SectionsTableID = @"SectionsTableID";
static NSString *TobyCellID = @"TobyCellID";

NSString *aName = [nameSection objectAtIndex:row];

if (aName == @"Toby")
{
TobyCell *cell = [tableView dequeueReusableCellWithIdentifier:TobyCellID];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TobyCell" owner:self options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[TobyCell class]])
cell = (TobyCell *)oneObject;
}
cell.lblName.text = [nameSection objectAtIndex:row];
return cell;
}
else
{
//standard cell loading code
}
}

我想要的是让Row等于My Name时触发if语句-非常令人兴奋。
if (aName == @"Toby")

我已经发出警报,并且正在设置“值”并将其设置为Toby,但是If语句不仅仅执行else部分。很明显,我很想念一些简单的事情。

我正在学习Objective-C

最佳答案

if语句:

if (aName == @"Toby")

比较指针,而不是字符串。你要:
if ([aName isEqualToString:@"Toby"])

这与纯C并没有太大的区别。您也不能使用 ==在此比较字符串。

关于iphone - 为什么我的if语句不触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1651450/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com