我編寫了一個方法,通過按鈕數組循環,並檢查一個字符串是否等於數組內的任何按鈕標題,但它不起作用,雖然字符串傳遞給該方法等於陣列內的一些字符串,這裏是我的代碼:問題比較在NSMutable陣列內的NSString
-(void)checkDuplicatesInSection:(NSString*)btnLabel
{
for (UIButton* btn in self.test) {
if([btnLabel isEqualToString:btn.titleLabel.text])
{
NSLog(@"Inside check Dublicates--->Title Existed");
} else {
NSLog(@"Inside check Dublicates--->Title Not Existed");
}
}
}
// self.test---> it's an array contains group of buttons
// btnLabel----> it's a string passed to that method
我不明白是爲什麼,當我運行程序時,我得到兩個Inside check Dublicates--->Title Existed
和"Inside check Dublicates--->Title Not Existed
。
這個問題很混亂。我清理了格式,但是能否重述或闡述您的問題? – 2012-03-24 19:37:40
if([btnLabel isEqualToString:btn.titleLabel.text]) 該語句不起作用,雖然我打印按鈕標題和數組工作正常,當我刪除btn.titleLabel.text並把一個常量字符串,有用!! – 2012-03-24 19:42:24
你可以註銷你的'self.test'數組嗎?其中一個指針可能不是'UIButton'。 – Gobot 2012-03-24 19:50:24