小编moz*_*zer的帖子

使用NSNumberFormatter将NSNumber转换为NSString

我在这个例子中转换NSNumberNSString假设所选择的键"theindex"1000000

NSNumber  *firstNumber = [tempDict objectForKey:@"theindex"];
NSString *convertNumber = [firstNumber stringValue];
Run Code Online (Sandbox Code Playgroud)

回归NSString"1000000"

我希望字符串的值为"1,000,000".

我不关心本地化,但从其他NSNumberFormatter应该实现的问题中理解.我不知道怎么做到这一点?

iphone cocoa-touch objective-c nsnumberformatter

7
推荐指数
1
解决办法
1万
查看次数

iOS部署目标设置为iOS 4.2.该应用程序是否会在运行早期版本iOS的设备上运行?

如果应用程序是在Xcode中编译并且其iOS部署目标设置为iOS 4.2,它是否会在运行早期版本iOS的设备上运行?该应用程序没有iOS 4独有的功能.我做了一个干净安装的Snow Leopard和XCode 3.2.5,并且早期版本的SDK不在那里进行测试.

iphone xcode ios

3
推荐指数
1
解决办法
3353
查看次数

在UITableView中按字母顺序显示.plist键值

我在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)

iphone objective-c plist uitableview ios

3
推荐指数
1
解决办法
4480
查看次数

实例变量在iOS应用程序中不保留值

我在我的身上宣布了这个伊娃

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)

iphone scope objective-c instance-variables ios

1
推荐指数
1
解决办法
2083
查看次数