NSDictionary *topic = [spaces objectAtIndex:i];
NSInteger topicid = [topic valueForKey:@"TOPICID"];
Run Code Online (Sandbox Code Playgroud)
当我运行这个并打印出主题时,我得到以下内容:
Printing description of topic:
<CFDictionary 0xdb2a70 [0x30307a00]>{type = mutable, count = 2, capacity = 12, pairs = (
10 : <CFString 0xdb5300 [0x30307a00]>{contents = "TOPICID"} = 29
12 : <CFString 0xdb53a0 [0x30307a00]>{contents = "TOPICNAME"} = <CFString 0xdb5360 [0x30307a00]>{contents = "zzzzzzzz"}
)}
Run Code Online (Sandbox Code Playgroud)
但是,当我查看topicid时,值始终是内存地址.我究竟做错了什么?
这似乎是一个非常愚蠢的问题,但我无法弄清楚为什么我会收到错误.
我有一个实例变量声明为:
NSInteger *scopeSelected;
Run Code Online (Sandbox Code Playgroud)
我正在使用此变量来跟踪在UISearchDisplay控制器中使用以下内容选择的范围:
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchScope:(NSInteger)searchOption {
scopeSelected=searchOption;
return YES;
}
Run Code Online (Sandbox Code Playgroud)
但是,我一直在分配线上抛出这个警告:
赋值从整数中生成指针而不进行强制转换
有人可以告诉我我的代码有什么问题吗?它不仅仅是NSInteger分配的NSInteger吗?
我试图testInt通过userInfo字段传递一个整数()NSTimer
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(count:) userInfo:testInt repeats:YES];
Run Code Online (Sandbox Code Playgroud)
但是我收到了一个不兼容的类型错误消息.
有谁知道如何将数字传递给count方法?
UITextField *textField;
NSInteger intRollNumber;
Run Code Online (Sandbox Code Playgroud)
我想从中获取rollNumber输入textField并将值存储到intRollNumber.
我是怎么做到的?因为我无法将字符串转换为整数.
在尝试为NSInteger创建类别时,编译器会抱怨它"无法找到'NSInteger'的接口声明".是否无法创建NSInteger类别?
一个简单的测试将显示编译器错误:
#import <Foundation/Foundation.h>
@interface NSInteger (NSInteger_Extensions)
-(NSInteger)simpleTest;
@end
#import "NSInteger_Extensions.h"
@implementation NSInteger (NSInteger_Extensions)
-(NSInteger)simpleTest {
return self + 5;
}
@end
Run Code Online (Sandbox Code Playgroud)
这有可能吗?
谢谢!
我正在构建一个UIPickerView,类似于UIDatePicker的自定义子类,timepicker样式.
无论如何,分钟组件应该每5分钟有一个数字,从00,05开始,然后是10,15等...
如何在00和05分钟标记处左侧获得零号码填充格式?
我怀疑我必须深入研究NSNumberFormatter类,但我没有任何经验,除了它看起来像一个可怕的类,我希望有人可以快速给我一个基本的实现.
我想在我的开头保持零NSInteger,但是当我NSLog这样时,零被移除.
NSInteger myInteger = 05;
NSLog("%d", myInteger);
Run Code Online (Sandbox Code Playgroud)
日志:5
我得到5而不是05.我怎样才能保持0整数的开头?
我有两个名为"domande"和"corrette"的NSInteger变量.我必须用它们执行这个操作:corrette*10/domande.我希望结果是一个浮点变量,所以我声明了一个"voto"变量:"float voto = corrette*10/domande;" .当我用NSLog输出"voto"的值时,得到结果的近似值,后跟".000000".
这是代码:
NSInteger domande = [numDomande integerValue];
NSInteger corrette = [numRisposteCorrette integerValue];
float voto = corrette*10/domande;
NSLog(@"float value is: %f", voto);
Run Code Online (Sandbox Code Playgroud)
当我为"domande"赋值7时,并且"corrette"值为4:voto = 5.000000相反它应该是voto = 5.71 ...
如何让除法返回不是转换为float的整数类型,而是直接浮点类型?
给出以下代码段:
- (void)doSomething
{
NSUInteger count;
}
Run Code Online (Sandbox Code Playgroud)
什么算?它保证是0吗?
我尝试将两个NSIntegers相乘,但Xcode给了我一个错误:
NSInteger singlePage = ((NSInteger)floor((scrollView.contentOffset.x * 2.0f + pageWidth) / (pageWidth * 2.0f)));
NSInteger page = singlePage * visiblePages;
Run Code Online (Sandbox Code Playgroud)
错误本身:
Invalid operands to binary expression ('NSInteger' (aka 'int') and 'NSInteger *' (aka 'int *'))
Run Code Online (Sandbox Code Playgroud)
NSInteger visiblePages已经定义并正在传递给方法.
我认为编译器认为*是指针符号而不是乘法符号.有没有其他方法来乘以两个NSIntegers?
nsinteger ×10
objective-c ×8
iphone ×4
ios ×2
categories ×1
cocoa ×1
int ×1
multiplying ×1
nsdictionary ×1
nsnumber ×1
nstimer ×1
pointers ×1
uidatepicker ×1
uipickerview ×1
uitextfield ×1
xcode ×1