有人可以帮我理解下面的方法是做什么的吗?
+ (Game *) shared
{
static Game *sharedSingleton;
@synchronized(self)
{
if (!sharedSingleton)
{
sharedSingleton = [[Game alloc] init];
}
}
return sharedSingleton;
}
Run Code Online (Sandbox Code Playgroud) 将数据从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) 我相信该#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) 另一个新手问题,就在我认为我开始在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) 我有一个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) 原谅我的"新手"问题,但问题是什么,"?" 在fololowing代码行中意味着什么?
self.navigationItem.leftBarButtonItem.title = (editing) ?
NSLocalizedString(@"Done", @"Done") : NSLocalizedString(@"Edit", @"Edit");
Run Code Online (Sandbox Code Playgroud) 我是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 …
objective-c ×6
ios ×2
iphone ×2
cocoa-touch ×1
core-data ×1
dateadd ×1
datetime ×1
import ×1
ios4 ×1
ios5 ×1
nsarray ×1
nsdictionary ×1
singleton ×1
t-sql ×1
xcode ×1