在UILabel中显示indexOfObject
我试图在在UILabel中显示indexOfObject,uilabel,type-conversion,Uilabel,Type Conversion,我试图在UILabel中显示NSArray中的对象数,作为UITabelViewCell的一部分: UILabel *numberLabel = (UILabel *)[cell viewWithTag:103]; numberLabel.numberOfLines = [self.inputValues indexOfObject:inputValue]; NSLog(@"rownumber is: %d", numberLabel.numberOfLines); NSLog为我提供了正确的
UILabel
中显示NSArray
中的对象数,作为UITabelViewCell
的一部分:
UILabel *numberLabel = (UILabel *)[cell viewWithTag:103];
numberLabel.numberOfLines = [self.inputValues indexOfObject:inputValue];
NSLog(@"rownumber is: %d", numberLabel.numberOfLines);
NSLog
为我提供了正确的编号,但标签仅显示默认的标题值。我错过了什么?不会抛出任何错误。我确信您希望:
UILabel *numberLabel = (UILabel *)[cell viewWithTag:103];
numberLabel.text = [NSString stringWithFormat:@"%d", [self.inputValues indexOfObject:inputValue]];
NSLog(@"rownumber is: %d", numberLabel.numberOfLines);
您需要设置标签的
text
属性。例如:
NSUInteger index = [self.inputValues indexOfObject:inputValue];
numberLabel.text = [NSString stringWithFormat:@"Row %lu", (unsigned long)index];
但是,似乎可以从单元格的索引路径使用行
,如下所示:
numberLabel.text = [NSString stringWithFormat:@"Row %ld", (long)indexPath.row];
那么,它应该显示什么呢?你不能在任何地方设置它的文本。。。另外,如果您将标签的高度(以行为单位)设置为
inputValue
?@H2CO3的索引,而我所掌握的信息有限,那么我假设OP将text
与numberOfLines
-查看NSLog
。真的,虽然,没有进一步澄清的OP,我猜。无论如何,您上次在UITableViewCell
中使用numberOfLines
是什么时候?那是我写我的@H2CO3的时候。这是真的-这根本不是(至少是我)每天都做的事情。@JFS“原始海报”。(you)@H2CO3(几乎)这里的每个人都知道如何读和写——但苹果的文档并不是很好的读物——它们往往很枯燥,只是更容易阅读其他内容。谢谢,第二种方法对我来说很好。我以前试过这个,但是错过了(long)
部分。在iOS上,NSUInteger
是unsigned int
,而NSInteger
是int
,因此可以使用%u
/%d
并省略强制转换。但是,在OSX上,NSInteger
是无符号长的
,NSInteger
是长的
。我有铸造的习惯,这样我就可以在iOS或OSX上使用相同的代码。谢谢!在养成习惯之前,我还需要学习更多。。。