我试图用自动文本换行创建UITextField,但我不能这样做.
每当我想制作一个计时器时,我就是:
[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应用程序中避免内存泄漏的正确方法.
我的应用程序有一个更新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中分析我的代码,它会说存在潜在的内存泄漏.
尝试运行以下命令时:genstrings ./Classes/*.m在终端上,我收到以下错误:Argument is not a literal String.有谁知道问题可能是什么?
我试图实现ASIHTTPRequest从服务器下载文件.我有一个选项是用户可以将下载添加到队列并ASINetworkQueue逐个处理文件下载.
我正在尝试实现一个功能,其中,如果用户丢失了他们的网络连接,我ASINetworkQueue应该连续轮询网络可达性.一旦连接再次可用,应用程序就会从停止的位置开始下载文件.
我不是要求代码,但如果有人可以帮我提供一系列提示,我将不胜感激.
ASIHTTPRequest方法
[request setAllowResumeForFileDownloads:YES];
Run Code Online (Sandbox Code Playgroud)
我遇到一个特定的错误; 我在这条线上得到"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) 我是否需要显式归零基元,即设置为BOOLs NO,将ints 设置为0?
我需要明确地分配NSString*到nil或@""?
我知道指针必须明确设置nil,否则它们可能会被垃圾填满.(或者仅适用于Objective-C++?)
我试图格式化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) 我开始在通用配置中开发应用程序,但后来需求发生变化,应用程序结果只是iPhone.现在,如何更改应用程序配置以满足此标准?
我最近开始处理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) objective-c ×9
cocoa-touch ×5
ios ×4
cocoa ×3
memory-leaks ×2
core-data ×1
foundation ×1
nsmenu ×1
nstimer ×1
primitive ×1
reachability ×1
uitextfield ×1