小编5lb*_*ass的帖子

帮助理解返回单例的类方法

有人可以帮我理解下面的方法是做什么的吗?

+ (Game *) shared
{
    static Game *sharedSingleton;

    @synchronized(self)
    {
        if (!sharedSingleton)
        {
            sharedSingleton = [[Game alloc] init];
        }
    }

    return sharedSingleton;
}
Run Code Online (Sandbox Code Playgroud)

singleton cocoa-touch objective-c singleton-methods ios

12
推荐指数
2
解决办法
6751
查看次数

不明白为什么DATEADD没有递增数据时间

将数据从Access迁移到SQL Server.SQL Server表将inst_id,cons_code和eff_date_time列定义为主键.来自访问的eff_date_time数据不是唯一的,所以我试图将秒字段增加一秒,所以我将有一个唯一的日期时间.我无法让DATEADD将日期增加1秒.附上是我的代码.我究竟做错了什么???

USE [CON-INST]  
GO

DECLARE  
@cv_InstId      VARCHAR(25),  
@cv_ConsCode    VARCHAR(10),  
@cv_EffDateTime DATETIME,  
@lv_count INT  

DECLARE BumpDate_Cursor CURSOR  
STATIC  
FOR  
          SELECT inst_id, cons_code, eff_date_time  
            FROM [CON-INST].[dba].[constants_temp]  
           ORDER BY inst_id  

OPEN BumpDate_Cursor

FETCH FIRST FROM BumpDate_Cursor  
 INTO @cv_InstId, @cv_ConsCode, @cv_EffDateTime

SET @lv_count = 1

// Debug statements  
PRINT '@cv_InstId = ' + @cv_InstId  
PRINT '@cv_ConsCode = ' + @cv_ConsCode  
PRINT '@cv_EffDateTime = ' + CONVERT(VARCHAR, @cv_EffDateTime)  
PRINT '@lv_count = ' + CONVERT(VARCHAR, @lv_count)  

-- Loop to iterate thru instruments identifying the …
Run Code Online (Sandbox Code Playgroud)

t-sql datetime dateadd

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

#ifdef __OBJC__在做什么,为什么下面列出了库?

我相信该#ifdef __OBJC__指令可确保我仅为Objective-C导入以下类库。在ifdef语句之后列出类库的目的是什么?这个代码示例不是要达到目的吗?

#ifdef __OBJC__
#import <foundation/foundation.h>
#import <uikit/uikit.h>
#import <coredata/coredata.h>
#endif
</coredata/coredata.h></uikit/uikit.h></foundation/foundation.h>
Run Code Online (Sandbox Code Playgroud)

import objective-c conditional-compilation ios4 ios

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

无法在NSManagedObject类上调用指定的初始化程序

另一个新手问题,就在我认为我开始在ios编程上获得一个非常小的处理时.啊! 我正在关注appcodeblog.com上的一个tutoria,我正在构建一个简单的标签栏应用程序,利用核心数据输入,显示和搜索度假目的地.我已经完成了教程,并有一个有效的应用程序,但我注意到当我选择"显示目的地"选项卡时,我收到以下错误.该应用程序似乎继续工作,但错误记录到控制台.我正在尝试调试问题并准确理解发生了什么,但我不太明白什么是错的.我"想"我的ShowDestinations.xib文件存在问题,我错误地将我的对象连接到xib中.任何帮助深表感谢.在此先感谢您的帮助和时间.

这是错误,"CoreDataTabBarTutorial [1262:207]无法在NSManagedObject类'Destination'上调用指定的初始值设定项.

我不确定要提供什么代码所以我开始通过显示我的头文件和实现文件ShowDistinationsViewController.h和ShowDestinationsViewController.m

ShowDistinationsViewController.h

#import <UIKit/UIKit.h>


@interface SearchDestinationsViewController : UIViewController {

    UISearchBar *destinationSearchBar;
    UITableView *searchTableView;

    NSFetchedResultsController *fetchedResultsController;
    NSManagedObjectContext *managedObjectContext;

    NSArray *fetchedObjects;

 }

@property (nonatomic, retain) IBOutlet UISearchBar *destinationSearchBar;
@property (nonatomic, retain) IBOutlet UITableView *searchTableView;

@property (nonatomic, retain) IBOutlet NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, retain) IBOutlet NSManagedObjectContext *managedObjectContext;

@end
Run Code Online (Sandbox Code Playgroud)

ShowDestinationsViewController.m

#import "ShowDestinationsViewController.h"
#import "Destination.h"

@implementation ShowDestinationsViewController

@synthesize destinationsTableView;
@synthesize destinationsArray;
@synthesize fetchedResultsController;
@synthesize managedObjectContext;

// Not sure where the following code came from so I commented it out!!! It didn't …
Run Code Online (Sandbox Code Playgroud)

xcode core-data objective-c

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

- [__ NSArrayI replaceObjectAtIndex:withObject:]:发送到实例的无法识别的选择器

我有一个Mutable NSArray存储对象类型(ids - NSNumber,NSString),它们将存储数字(1,2,3,4等),操作(+, - ,/,*等)和变量( x,y,z等).我将变量和相关值存储在NSDictionary中,键的NSStrings等于x,y,z,NSNumber值分别为5,5,2.我想将我的NSArray中的变量替换为存储在我的NSDictionary中的实际值.当我尝试替换对象时,我不断收到以下错误.请帮忙.

- [__ NSArrayI replaceObjectAtIndex:withObject:]:发送到实例的无法识别的选择器

        NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:
                              [NSNumber numberWithDouble:5],@"x",  
                              [NSNumber numberWithDouble:5],@"y", 
                              [NSNumber numberWithDouble:2],@"z", 
                              nil];

+ (double)runProgram:(id)program
 usingVariableValues:(NSDictionary *)variableValues;
{
    // introspection - ensure program is NSArray and variableValues is NSDictionary
    if ([program isKindOfClass:[NSArray class]] && [variableValues isKindOfClass:    [NSDictionary class]])
    {
        // array for program stack
        NSMutableArray *stack = [program copy];

        // Loop to replace variables with actual values in NSDictionary
        for (NSUInteger i = 0; i < [stack count]; i++) …
Run Code Online (Sandbox Code Playgroud)

objective-c nsdictionary nsarray ios5

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

什么是"?" 在下面的陈述中表示

原谅我的"新手"问题,但问题是什么,"?" 在fololowing代码行中意味着什么?

self.navigationItem.leftBarButtonItem.title = (editing) ?
    NSLocalizedString(@"Done", @"Done") : NSLocalizedString(@"Edit", @"Edit");
Run Code Online (Sandbox Code Playgroud)

iphone objective-c

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

为什么'TableViewController'可能无法响应'-setNames:'

我是iPhone dev和Object-C的菜鸟.不知道为什么我的'TableViewController'可能无法响应'-setNames:'任何帮助将不胜感激.

头文件

#import <UIKit/UIKit.h>
#import "FishViewController.h"

@interface FishTableViewController : UITableViewController {
    NSArray* fishNames;
}

+ (FishTableViewController*) fishTableViewControllerWithFishNames:(NSArray*)fishSubCategory;

@property (nonatomic, retain) NSArray* fishNames;
@end
Run Code Online (Sandbox Code Playgroud)

实施文件.

#import "FishTableViewController.h"

#define FishTableViewControllerNibName @"FishTableViewController"

@implementation FishTableViewController

@synthesize fishNames;

+ (FishTableViewController*) fishTableViewControllerWithFishNames:(NSArray*)fishSubCategory {
    // Warning occurs on the following line
    FishTableViewController* retController = [[FishTableViewController alloc] initWithNibName:FishTableViewControllerNibName bundle:nil];

    [retController setfishNames:fishSubCategory];

    return [retController autorelease];
}
Run Code Online (Sandbox Code Playgroud)

调试控制台输出

2011-01-03 13:06:21.287 FishID[826:207] -[FishTableViewController setfishNames:]: unrecognized selector sent to instance 0x5d0d340
2011-01-03 13:06:21.289 FishID[826:207] *** Terminating app due to uncaught exception …

iphone objective-c

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