- (IBAction)convert_button:(id)sender {
NSString * binary_input = _binary_field.text;
if(binary_input!=NULL)
{
int count, total, i, j, tmp;
total = 0;
count = binary_input.length;
for (i = 0; i <= count; i++) {
if (binary_input[count-i] == '1') {//error here saying Expected method to read array element not found of object type 'NSString *'
tmp = 1;
for (j = 1; j < i; j++)
tmp *= 2;
total += tmp;
}
}
long decimal_value = strtol([binary_input UTF8String], NULL, 2);
NSString *resultString = [[NSString alloc]
initWithFormat: @"%li", decimal_value];
_decimal_output.text = resultString;
}
}預計方法來讀取數組元素沒有找到對象類型「的NSString *」
我得到一個錯誤在我的if語句錯誤代碼評論說,讀數組元素不期望方法找到的對象類型'NSString *'
我是新來的objective-c,主要做了C++,任何幫助在如何解決錯誤的讚賞,該邏輯對我有意義。
你不能索引一個NSString。請查閱文檔以瞭解如何訪問個人角色。 – 2014-09-24 01:29:36
改爲使用'[binary_input characterAtIndex:index]'。 – KudoCC 2014-09-24 01:34:43
解決了問題KudoCC – user3746000 2014-09-24 02:57:13