我在这个例子中转换NSNumber为NSString假设所选择的键"theindex"是1000000
NSNumber *firstNumber = [tempDict objectForKey:@"theindex"];
NSString *convertNumber = [firstNumber stringValue];
Run Code Online (Sandbox Code Playgroud)
回归NSString"1000000"
我希望字符串的值为"1,000,000".
我不关心本地化,但从其他NSNumberFormatter应该实现的问题中理解.我不知道怎么做到这一点?
如果应用程序是在Xcode中编译并且其iOS部署目标设置为iOS 4.2,它是否会在运行早期版本iOS的设备上运行?该应用程序没有iOS 4独有的功能.我做了一个干净安装的Snow Leopard和XCode 3.2.5,并且早期版本的SDK不在那里进行测试.
我在iOS .plist中有一系列字典,结构类似于以下内容:
<plist version="1.0">
<array>
<dict>
<key>name</key>
<string>Afghanistan</string>
<key>government</key>
<string>Islamic Republic</string>
<key>population</key>
<integer>29121286
</integer>
</dict>
<dict>
<key>name</key>
<string>Albania</string>
<key>government</key>
<string>Emerging Democracy</string>
<key>population</key>
<integer>2986952</integer>
</dict>
Run Code Online (Sandbox Code Playgroud)
我正在尝试将<key>name</key>每个字典加载 到NSTableViewCell中,然后在NSTableView中按字母顺序显示它们,类似于iOS中的Contacts App.
下面是我的ViewControllers .h和.m.排序正常,但我无法将结果加载到TableViewCells中?
FirstViewController.h
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController <UITableViewDelegate,UITableViewDataSource>
{
NSArray *sortedCountries;
}
@property (nonatomic, retain) NSArray *sortedCountries;
@end
Run Code Online (Sandbox Code Playgroud)
FirstViewController.m
#import "FirstViewController.h"
@implementation FirstViewController
@synthesize sortedCountries;
-(void)viewDidLoad {
NSString *path = [[NSBundle mainBundle] pathForResource:@"countries"ofType:@"plist"];
NSArray *countries = [NSArray arrayWithContentsOfFile:path];
NSSortDescriptor *descriptor = [[[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES] autorelease];
NSArray *sortedCountries = …Run Code Online (Sandbox Code Playgroud) 我在我的身上宣布了这个伊娃
ViewController.h
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
NSArray *sortedCountries;
}
@property (nonatomic, retain) NSArray *sortedCountries;
@end
Run Code Online (Sandbox Code Playgroud)
在ViewController.m中,sortedCountries -(void)ViewDidLoad{}通过存储已排序的.plist的结果来完成它的工作 .
什么时候
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {}
Run Code Online (Sandbox Code Playgroud)
在下面调用,sortedCountries返回 (null)
为什么sortedCountries的值不存在?我retain在第一个函数中添加了一个......我想我在这里缺少一个基本的Objective-C租户.
ViewController.m
#import "FirstViewController.h"
@implementation FirstViewController
@synthesize sortedCountries;
-(void)viewDidLoad {
NSString *path = [[NSBundle mainBundle] pathForResource:@"countries" ofType:@"plist"];
NSArray *countries = [NSArray arrayWithContentsOfFile:path];
NSSortDescriptor *descriptor = [[[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES] autorelease];
NSArray *sortedCountries = [[countries sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]]retain];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView …Run Code Online (Sandbox Code Playgroud)