如果我将UISwitch控制器切换到"关闭"并离开视图控制器并返回到视图控制器,它将显示UISwitch"打开"(默认值)而不是"关闭".从/向视图控制器切换时如何保存UISwitch控制器的值?
- (void)controlsEnabled:(BOOL)enabled
{
self.onandoffSwitch.enabled = enabled;
if (enabled)
{
NSLog(@"ON");
}
else
{
NSLog(@"OFF");
}
}
Run Code Online (Sandbox Code Playgroud) 我正在学习开发iOS应用程序的教程.我正在使用核心数据.该应用程序的第一个视图是RootViewController.所有Core Data堆栈都在AppDelegate文件中.这是代码的一部分AppDelegate.m,它调用RootViewController文件:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Fetch the data to see if we ought to pre-populate
NSError *error = nil;
if (![[self fetchedResultsController] performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
[self loadFavoriteThingsData];
RootViewController *rootViewController = (RootViewController *)[navigationController topViewController];
[rootViewController setManagedObjectContext:[self managedObjectContext]];
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
现在,在应用程序的另一部分,我需要打开一个新的视图控制器,它是一个副本RootViewController,被称为DoneViewController,但使用其他NSPredicates来显示其他核心数据对象.
在RootViewController那里有一个打开MenuViewController文件的按钮,从那里我尝试DoneViewController使用以下方法打开:
- (IBAction)doneToDoaction:(id)sender …Run Code Online (Sandbox Code Playgroud) 我经常搜索并阅读了很多关于MVC概念的内容.但我仍然不知道如何将它们连接在一起.假设我有一个控制器类,视图类和模型类.如果用户在该视图中执行了某些操作,则视图应通知控制器操作,并且控制器可能需要与模型通信以获取某些数据.
我之前做的是创建一个"视图控制器",它具有该视图的视图和一些动作.有时候没有模特.所有数据都通过参数传递.如果有一些模型,其中一些是单身,所以我可以到处获取它.
我正在尝试从网站获取数据以在表格视图中显示它
我的代码:
-(void)loadTutorials {
NSURL *url = [NSURL URLWithString:[@"http://www.example.com/search?q=" stringByAppendingString:self.searchString]];
NSURLRequest *UrlString = [[NSURLRequest alloc] initWithURL:url];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:UrlString
delegate:self];
[connection start];
NSLog(@"Started");
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
TFHpple *tutorialsParser = [TFHpple hppleWithHTMLData:data];
NSString *tutorialsXpathQueryString = @"//div[@id='header']/div[@class='window']/div[@class='item']/div[@class='title']/a";
NSArray *tutorialsNodes = [tutorialsParser searchWithXPathQuery:tutorialsXpathQueryString];
NSMutableArray *newTutorials = [[NSMutableArray alloc] init];
for (TFHppleElement *element in tutorialsNodes) {
Data *tutorial = [[Data alloc] initWithTitle: [[element firstChild] content]
Url: [@"http://www.example.com" stringByAppendingString: [element objectForKey:@"href"]]
];
[newTutorials addObject:tutorial];
}
_objects = newTutorials; …Run Code Online (Sandbox Code Playgroud) 我正在制作一个应用程序,您需要使用 4 位密码登录,但一次只能有一个密码。我正在尝试将其保存到核心数据,但每当用户添加新密码时,它只会将其添加到长列表中。如何限制一个实体只有一个它自己的实例?
这是我的代码,以防万一它会有所帮助:
-(BOOL)savePassword:(NSString*)password{
AppDelegate * appDelegate = [[AppDelegate alloc]init];
NSManagedObjectContext * context = [appDelegate managedObjectContext];
AppData * appData = (AppData*)[NSEntityDescription insertNewObjectForEntityForName:@"AppData" inManagedObjectContext:context];
appData.password = password;
NSError *error;
if (![context save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"AppData" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
if (fetchedObjects == nil) {
NSLog(@"There was an error:%@",error);
}
for (AppData * adata in fetchedObjects) {
NSLog(@"Password:%@",adata.password);
}
return …Run Code Online (Sandbox Code Playgroud) -(void)showLog
{
NSMutableString* msgStr = nil;
msgStr = [NSMutableString stringWithFormat:@"%s","Log :"];
//show Log
[msgStr release];
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码.我经常从一个线程调用这个函数.我已经禁用了ARC,我正在使用xcode 5中的iOS 7测试iPad Mini,在XCode 5中,它显示了连续的内存分配.即使我发布了这个,msgStr为什么它会显示内存分配的增量?
任何帮助或建议都会很棒.
我有一个NSMutableArray.当我使用时NSLog,这是输出:
2012-12-15 17:58:28.849 Splash-it[504:907] (
"Open House New York",
"Boston Athletic Association",
"Autofest Tanzania"
),
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到NSString这些标题中的一个(考虑到标题会改变,我想我需要使用objectAtIndex但我不认为它会在这种情况下起作用)?
例如
NSString = @"Boston Athletic Association"
Run Code Online (Sandbox Code Playgroud) 我是IOS开发的新手,我需要使用本机方法将数据发布到服务.
我想我需要做这样的事情?
NSString *content = @"field1=42&field2=Hello";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.mywebsite.co.uk/SendEmail.svc/request"]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[content dataUsingEncoding:NSISOLatin1StringEncoding]];
// generates an autoreleased NSURLConnection
[NSURLConnection connectionWithRequest:request delegate:self];
Run Code Online (Sandbox Code Playgroud)
因为我不确定,我会这样做吗?我可以通过手动构建URL或在fiddler中发布json来成功发布到服务.
我有一个解析HTML的方法.在那里有一个if/else语句:
if ((NSNumber1 == NSNumber2)) {
NSLog(@"dafuq1?");
} else {
NSLog(@"dafuq2?");
}
Run Code Online (Sandbox Code Playgroud)
日志有时像这样:
...:dafuq1?
...:dafuq2?
所以两个部分都被调用了.但有时候只有其中一个被召唤!为什么?
顺便说一句.iOS 7.0.4,Xcode 5.0.1
并且
(NSNumber1 == NSNumber2)是真实的
ios ×7
objective-c ×6
core-data ×2
asynchronous ×1
json ×1
nsnumber ×1
post ×1
uiswitch ×1
web-services ×1
xcode ×1