小编Jos*_*ell的帖子

UITextField具有自动换行功能

我试图用自动文本换行创建UITextField,但我不能这样做.

cocoa-touch objective-c uitextfield ios

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

NSTimer的内存管理 - 是否需要将其分配给变量?

每当我想制作一个计时器时,我就是:

[NSTimer scheduledTimerWithTimeInterval:5.0 
                                 target:self 
                               selector:@selector(someMethod) 
                               userInfo:nil 
                                repeats:NO];
Run Code Online (Sandbox Code Playgroud)

而不是

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5.0 
                                                  target:self 
                                                selector:@selector(someMethod) 
                                                userInfo:nil 
                                                 repeats:NO];
Run Code Online (Sandbox Code Playgroud)

第一个是内存泄漏吗?使用它们的正确方法是什么?

cocoa memory-leaks objective-c nstimer foundation

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

更新NSMenu中的项目时的内存管理

我想知道这是否是在Cocoa应用程序中避免内存泄漏的正确方法.

我的应用程序有一个更新NSMenu项目的方法:

//Remove and Release old Status Scan Menu:
if ([statusMenuScansMenu numberOfItems] !=0) {
    for (NSMenuItem *menueItemToBeReleased in [statusMenuScansMenu itemArray]) {
        [statusMenuScansMenu removeItem:menueItemToBeReleased];
        [menueItemToBeReleased release];
    }
}

//New Status Scan Menu:
for (MyObject* myObject in myArray) {
    NSMenuItem * scanMenuItem = [[NSMenuItem alloc] init];
    [scanMenuItem setTitle:[myObject name]];
    [statusMenuScansMenu addItem:scanMenuItem];
}
Run Code Online (Sandbox Code Playgroud)

如您所见,在添加新项目之前,我删除所有以前的项目并发release送给他们.然后我添加新的.

这是内存管理的最佳方式吗?

如果我在Xcode 4.1中分析我的代码,它会说存在潜在的内存泄漏.

cocoa memory-leaks memory-management objective-c nsmenu

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

运行genstrings命令时获取错误"参数不是文字字符串"

尝试运行以下命令时:genstrings ./Classes/*.m在终端上,我收到以下错误:Argument is not a literal String.有谁知道问题可能是什么?

objective-c

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

轮询网络以确定网络是否可达?

我试图实现ASIHTTPRequest从服务器下载文件.我有一个选项是用户可以将下载添加到队列并ASINetworkQueue逐个处理文件下载.

我正在尝试实现一个功能,其中,如果用户丢失了他们的网络连接,我ASINetworkQueue应该连续轮询网络可达性.一旦连接再次可用,应用程序就会从停止的位置开始下载文件.

我不是要求代码,但如果有人可以帮我提供一系列提示,我将不胜感激.


为了使我的应用程序从中断的位置下载文件,我正在使用该ASIHTTPRequest方法

[request setAllowResumeForFileDownloads:YES];
Run Code Online (Sandbox Code Playgroud)

user-experience objective-c asihttprequest reachability ios

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

SIGABRT访问NSMutableArray

我遇到一个特定的错误; 我在这条线上得到"SIGABRT":

cell.textLabel.text = [collections objectAtIndex: [indexPath row]];
Run Code Online (Sandbox Code Playgroud)

我的头文件:

#import <UIKit/UIKit.h>

@interface CollectionsViewController : UITableViewController {
    NSMutableArray *collections;
    NSMutableData *responseData;
}
@property (nonatomic, retain) NSMutableArray *collections;

@end
Run Code Online (Sandbox Code Playgroud)

和实施文件:

#import "CollectionsViewController.h"
#import "JSON.h"


@implementation CollectionsViewController
@synthesize collections;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    // …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch objective-c nsmutablearray ios

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

原语是否需要初始化为零?

我是否需要显式归零基元,即设置为BOOLs NO,将ints 设置为0?

我需要明确地分配NSString*到nil或@""?

我知道指针必须明确设置nil,否则它们可能会被垃圾填满.(或者仅适用于Objective-C++?)

primitive initialization objective-c

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

将浮点数格式化为NSString时,会截断额外的零

我试图格式化float如下:

1.1500将显示为"$ 1.15"
1.1000将显示为"$ 1.10"
1.0000将显示为"$ 1.00"
1.4710将显示为"$ 1.471"
1.4711将显示为"$ 1.4711"

我试过了

NSString *answer = [NSString stringWithFormat:@"$ %.2f",myvalue];
Run Code Online (Sandbox Code Playgroud)

cocoa cocoa-touch objective-c number-formatting

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

将通用应用程序转换为仅iPhone应用程序

我开始在通用配置中开发应用程序,但后来需求发生变化,应用程序结果只是iPhone.现在,如何更改应用程序配置以满足此标准?

cocoa-touch ios ios-universal-app

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

应用程序关闭80%的时间后,保存的核心数据不会保留

我最近开始处理Core Data,在我的测试中,我发现大约有20%的时间数据实际保存到数据库中.剩下的时间,它只是临时保存,而应用程序正在运行.如果我重新启动,我保存的最后一个数据会丢失.

有谁知道是什么问题?

这是代码:

//Save data
NSEntityDescription *users = [NSEntityDescription insertNewObjectForEntityForName:@"Users" inManagedObjectContext:document.managedObjectContext];
[users setValue:@"Name Test" forKey:@"name"];
[users setValue:[NSNumber numberWithInt:20] forKey:@"age"];
[users setValue:@"Some Country" forKey:@"location"];


//Debugging
//no error ever shows up
NSError *error;
if(![document.managedObjectContext save:&error]) {
    NSLog(@"Error: %@", error);
}

//this is just to show that the problem may not be with my UIManagedDocument (self.document), since the NSLog never gets called.
if(self.document.documentState != UIDocumentStateNormal) {
    NSLog(@"Document is not opened");
}
//End of debugging


//Fetch all the data from the entity
NSFetchRequest …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch core-data objective-c

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