小编Lor*_*o B的帖子

离开视图控制器时,UISwitch不会保持其值

如果我将UISwitch控制器切换到"关闭"并离开视图控制器并返回到视图控制器,它将显示UISwitch"打开"(默认值)而不是"关闭".从/向视图控制器切换时如何保存UISwitch控制器的值?

- (void)controlsEnabled:(BOOL)enabled
{
    self.onandoffSwitch.enabled = enabled;   
    if (enabled)
    {
        NSLog(@"ON");    
    }
    else
    {
        NSLog(@"OFF");     
    }
}
Run Code Online (Sandbox Code Playgroud)

objective-c uiviewcontroller uiswitch ios

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

managedObjectContext无法识别的选择器发送到实例

我正在学习开发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)

core-data nsmanagedobjectcontext ios

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

模型,视图和控制器之间的连接

我经常搜索并阅读了很多关于MVC概念的内容.但我仍然不知道如何将它们连接在一起.假设我有一个控制器类,视图类和模型类.如果用户在该视图中执行了某些操作,则视图应通知控制器操作,并且控制器可能需要与模型通信以获取某些数据.

  1. 现在,视图是否持有对控制器的引用?控制器是否具有该模型的属性?或者他们只是使用像"包括"?
  2. 数据保存在内存或数据库中?内存意味着存储在变量中.
  3. 更复杂的情况,用户的一个动作可能需要涉及许多控制器和模型.如何协调他们?

我之前做的是创建一个"视图控制器",它具有该视图的视图和一些动作.有时候没有模特.所有数据都通过参数传递.如果有一些模型,其中一些是单身,所以我可以到处获取它.

model-view-controller ios

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

NSURLConnection didReceiveData没有加载数据

我正在尝试从网站获取数据以在表格视图中显示它

我的代码:

-(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)

asynchronous objective-c nsurlconnection ios

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

Core Data 中只有一个实体实例

我正在制作一个应用程序,您需要使用 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)

core-data objective-c nsmanagedobject ios

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

如何在iOS7中安全地释放NSMutableString

-(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为什么它会显示内存分配的增量?

任何帮助或建议都会很棒.

memory-management objective-c nsmutablestring

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

NSMutableArray:获取特定对象

我有一个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)

xcode objective-c nsmutablearray ios

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

在iPhone应用程序中将数据发布到WCF服务?

我是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来成功发布到服务.

post json web-services ios

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

if和else语句都是随机调用的

我有一个解析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)是真实的

objective-c nsnumber

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