【问题标题】:Why not I return lbl_esdeger.text at if condition?为什么我不在 if 条件下返回 lbl_esdeger.text?
【发布时间】:2012-08-31 09:03:36
【问题描述】:

为什么我的 lbl_esdeger.text 字符串不能取值?感谢您的帮助

selectedCountry = @"Kanıt"; lblText.text = selectedCountry;

titlearray = [[NSMutableArray alloc]init];
//KANAL D
[titlearray addObject:@"Annem Uyurken"];
[titlearray addObject:@"Arka Sokaklar"];
[titlearray addObject:@"Kanıt"];
[titlearray addObject:@"Kötü Yol"]; 


int i;
for (i=0; i<[titlearray count]; i++) 
{
    if ([titlearray objectAtIndex:i] == selectedCountry) 
    {
        lbl_esdeger.text = [titlearray objectAtIndex:i];
        NSLog(@"--- %@ --- %@",[titlearray objectAtIndex:i],selectedCountry);
    }
}

【问题讨论】:

  • 我的回答是否解决了您的问题?如果有,请考虑accepting吧。

标签: xcode arrays nsstring uilabel


【解决方案1】:

你应该在 if 条件下使用 isEqualToString 方法比较字符串:

if ([[titlearray objectAtIndex:i] isEqualToString:selectedCountry])
                                  ^^^^^^^^^^^^^^^

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-12
    • 1970-01-01
    • 2021-02-22
    • 2019-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多