我有一个菜单让用户选择一个国家.与地址字段中的contacts.app国家/地区菜单中的内容完全相同.
有谁知道获取国家列表的简单方法?我已经使用NSLocale来生成一系列国家,但遗憾的是它只是国家代码而不是人类可读的等价物.我不想'GB'我想要英国.
我用这段代码设置我的常量
// Constants.h
extern NSInteger const KNameIndex;
// Constants.m
NSInteger const KNameIndex = 0;
Run Code Online (Sandbox Code Playgroud)
在导入Constant.h文件的文件中的switch语句中,我有:
switch (self.sectionFromParentTable) {
case KNameIndex:
self.types = self.facilityTypes;
break;
...
Run Code Online (Sandbox Code Playgroud)
我在编译时遇到错误:"错误:case标签不会减少为整数常量"
什么想法可能搞砸了?
如果我声明一个字符串常量如下:
你应该创建一个像头文件
// Constants.h
extern NSString * const MyFirstConstant;
extern NSString * const MySecondConstant;
//etc.
Run Code Online (Sandbox Code Playgroud)
您可以将此文件包含在使用常量的每个文件中,也可以包含在项目的预编译头中.
您可以在.m文件中定义这些常量
// Constants.m
NSString * const MyFirstConstant = @"FirstConstant";
NSString * const MySecondConstant = @"SecondConstant";
Run Code Online (Sandbox Code Playgroud)
如何定义整数常量?
看起来好像NSNumberFormatter's设置自定义的方法formatters.setFormat:在iPhone上不可用...
这样......崩溃我的应用程序:
NSNumberFormatter *lengthFormatter = [[NSNumberFormatter alloc] init];
[lengthFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[lengthFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
[lengthFormatter setFormat:@"#,##0.0M"];
Run Code Online (Sandbox Code Playgroud)
这是否发生在其他人身上?
谢谢,
丹**以下答案.NSNumberFormatter也有称为setPositiveFormat: setNegativeFormat:替换折旧setFormat:**的方法
如何使用touchXML解析此XML?我想将所有属性存储为字典中的键/值对.
<Player PlayerName="Padraig HARRINGTON" CurrentPosition="1" CurrentRank="1"
Country="IRL" NumberOfHolesPlayed="18" ParRelativeScore="+3">
<RoundScore RoundNumber="1" Score="74" />
<RoundScore RoundNumber="2" Score="68" />
<RoundScore RoundNumber="3" Score="72" />
<RoundScore RoundNumber="4" Score="69" />
</Player>
<Player PlayerName="Ian POULTER" CurrentPosition="2" CurrentRank="2" Country="ENG"
NumberOfHolesPlayed="18" ParRelativeScore="+7">
<RoundScore RoundNumber="1" Score="72" />
<RoundScore RoundNumber="2" Score="71" />
<RoundScore RoundNumber="3" Score="75" />
<RoundScore RoundNumber="4" Score="69" />
</Player>
<Player PlayerName="Henrik STENSON" CurrentPosition="3" CurrentRank="T3" Country="SWE"
NumberOfHolesPlayed="18" ParRelativeScore="+9">
<RoundScore RoundNumber="1" Score="76" />
<RoundScore RoundNumber="2" Score="72" />
<RoundScore RoundNumber="3" Score="70" />
<RoundScore RoundNumber="4" Score="71" />
</Player>
Run Code Online (Sandbox Code Playgroud)
我没有问题是XML格式如下:
<Player>
<Country>UK</Country>
<NumberOfHolesPlayed>12</NumberOfHolesPlayed> …Run Code Online (Sandbox Code Playgroud) 在开发我的应用程序时,我逐渐意识到我的大多数应用程序崩溃都源于糟糕的内存管理.
我知道我可以通过NSLog打印或记录保留计数(@"保留计数为:%d",[myInstance retainCount]);
但是不是有更好的,更少手动的方法吗?可能是对象和实例的直观表示?
回答.干杯,亚当和杰森.:-)
NSBeep()iPhone上是否存在?我只想播放一个简短的错误声音,表示按下的键不是合法字符.我会在我的textField委托中播放这个,它会抛弃非法字符.
我想在我的Xcode iPhone项目中使用clang.然而,这是入门指南:
http://clang.llvm.org/get_started.html
我已经和Xcode合作了一年,但这远远不能让我理解!谁能用英语解释如何在我现有的iPhone项目中安装和使用Clang?我不熟悉从控制台加载东西.
谢谢!
担
声明是:
//Pass the copy onto the child controller
self.childController.theFoodFacilityCopy = [self.theFoodFacility copy];
Run Code Online (Sandbox Code Playgroud)
我的财产设定为:
@property (nonatomic, retain) FoodFacility *theFoodFacilityCopy;
Run Code Online (Sandbox Code Playgroud)
我认为我有泄漏的原因是因为copy保留了值,然后我的点语法属性也保留了该值.双重保留.
编写上述陈述的正确方法是什么?
好吧,我知道这个错误主要来自发送方法调用或尝试访问已经解除分配的变量.
这是问题所在:
.h
@interface TimeEntry : NSObject <NSCopying, NSCoding> {
NSDate *from;
NSDate *to;
NSString *information;
}
@property (nonatomic, retain) NSDate *from;
@property (nonatomic, retain) NSDate *to;
@property (nonatomic, copy) NSString *information;
@end
Run Code Online (Sandbox Code Playgroud)
而且我的班级是dealloc.
-(void)dealloc{
[super dealloc];
[to release];
[from release];
[information release];
}
Run Code Online (Sandbox Code Playgroud)
当我收到EXC_BAD_ACCESS错误时,这是追溯的事情

所以我正在向已经解除分配的对象发送消息?
所以我打开NSZombie,这停止了我的崩溃.它并没有像我希望的那样给我一些可爱的崩溃报告.相反,它只是让程序崩溃.
在上面的dealloc方法中,如果我注释掉[发布]和[从发布]应用程序不会崩溃.如果我只注释其中一个......它不会崩溃.在调试窗口中往返有不同的内存地址.
记忆管理怎么这么难!!!!
有人提出任何线索吗?
谢谢,
担
- (id)copyWithZone:(NSZone *)zone {
PoolFacility *copy = [[[self class] allocWithZone:zone]init];
copy.name = [self.name copy];
copy.type = [self.type copy];
copy.phoneNumber = [self.phoneNumber copy];
//make sure I get proper copies of my dictionaries
copy.address = [self.address mutableCopy];
copy.webAddress = [self.webAddress copy];
copy.prices = [self.prices mutableCopy];
copy.pools = [self.pools mutableCopy];
return copy;
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以看到任何内存泄漏?
这是属性类型:
NSString *name;
NSString *type;
NSMutableDictionary *address;
NSString *phoneNumber;
NSString *webAddress;
NSMutableArray *prices;
NSMutableArray *pools;
Run Code Online (Sandbox Code Playgroud)
以下是属性声明:
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *type;
@property (nonatomic, copy) …Run Code Online (Sandbox Code Playgroud) 我的代码看起来像这样
NSNumber *inputToNumber = [NSNumber numberWithFloat:[textField.text floatValue]];
Run Code Online (Sandbox Code Playgroud)
textfield中的值实际上是一个电话号码.它作为恼人的(2.0)78966e + 08存储在NSNumber中
我怎样才能让NSNumber将其存储为0207896608?
我使用此代码复制和我的类的实例
//Create the copy and pass it onto edit controller
PoolFacility *poolCopy = [self.thePoolFacility copy];
self.childController.thePoolFacilityCopy = poolCopy;
[poolCopy release];
Run Code Online (Sandbox Code Playgroud)
现在,当我在调试器中查看变量时,为什么某些类的字段具有相同的内存地址?他们不应该独立吗?根据Apple的说法
NSCopying协议声明了一种提供对象功能副本的方法."复制"的确切含义因类而异,但复制必须是功能独立的对象,其值与复制时的原始值相同.
这两个实例是poolCopy和原始的thePoolFacility

我的类复制方法如下所示:
- (id)copyWithZone:(NSZone *)zone {
PoolFacility *copy = [[[self class] allocWithZone:zone]init];
copy.name = [self.name copy];
copy.type = [self.type copy];
copy.phoneNumber = [self.phoneNumber copy];
//make sure I get proper copies of my dictionaries
copy.address = [self.address mutableCopy];
copy.webAddress = [self.webAddress copy];
copy.prices = [self.prices mutableCopy];
copy.pools = [self.pools mutableCopy];
return copy;
}
Run Code Online (Sandbox Code Playgroud) cocoa-touch ×11
iphone ×10
objective-c ×9
ios ×2
clang ×1
cocoa ×1
llvm ×1
memory-leaks ×1
phone-number ×1
properties ×1
touchxml ×1
xcode ×1
xml ×1