小编Mat*_*uch的帖子

NSDate dateByAddingTimeInterval减去天数错误地更改时间

我错过了一些关于NSDate dateByAddingTimeInterval如何使用几天的内容?这是我从特定日期(AIDate)减去33天的代码.AIDate的时间值为00:00 PST.

activityOne.ActivityDateTime = [AIDate dateByAddingTimeInterval:-33*24*60*60];
Run Code Online (Sandbox Code Playgroud)

如果AIDate等于太平洋标准时间4-9-2013 00:00,则上述代码将减去33天和1小时,其工作时间为太平洋标准时间3-6-2013 23:00.

iphone cocoa-touch objective-c nsdate ios

5
推荐指数
2
解决办法
3980
查看次数

UITableView使重新加载旧图像的单元格出列

我知道这已被问过很多次,但是请耐心等待,因为我已经尝试了很多时间来寻找解决方案.

我有一个rss解析器,一个tableview,其中包含:文本,细节和设置为AccessoryDisclosureIndicator.view的图像.

使用简单的GCD异步加载图像很快:快速滚动数百个结果.没有滞后,如果我有良好的连接就没有错误.

问题是,一瞬间 - 它们在负载上闪烁,因为该单元正在被重用.此外,如果连接不好,它有时会留下散乱的图像但文本/细节是正确的,只有图像是旧的...所以让我重复一遍,文本/细节更新正常,永远不会重新排队错误,只是图像有时很少在错误的连接上排队错误/癫痫发作 - 快速来回滚动.

我的问题,有人可以帮我缓存/标记cell.accs.views吗?我尝试设置cellID但是我的实现有问题.如果连接从不减慢,我的下面的代码工作得很好,重新排队我不介意的单元格只是轻微的闪烁.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

    [cell.textLabel setNumberOfLines:3];
    cell.textLabel.font = [UIFont boldSystemFontOfSize:14.0];

    [cell.detailTextLabel setNumberOfLines:3];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:12.0];
    cell.detailTextLabel.textColor = [UIColor blackColor];
}

RSSItem * rssItem = (RSSItem *)(_rssParser.rssItems)[indexPath.row];

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,  0ul);
dispatch_async(queue, ^{
    //This is what you will load lazily
    NSData   *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:rssItem.imageURL]];
    dispatch_sync(dispatch_get_main_queue(), …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios

5
推荐指数
2
解决办法
7945
查看次数

试图在Swift中使用Objective-C编写的委托方法抛出"无法找到协议声明"

我有一个使用Salesforce SDK的现有Sample Objective-C应用程序.我试图将它转换为一次使用Swift一类.Salesforce SDK有一个名为'SFRestRequest.h'的类,它具有'SFRestDelegate'委托.

在Objective C中,我有一个名为'RootViewController.h'的类,它是UITableViewController的子类.它实现了SFRestDelegate.它工作正常.

//RootViewController.h
#import <UIKit/UIKit.h>
#import "SFRestAPI.h"

@interface RootViewController : UITableViewController <SFRestDelegate> {

    NSMutableArray *dataRows;
    IBOutlet UITableView *tableView;    

}
Run Code Online (Sandbox Code Playgroud)

我正在尝试创建一个RootVC.swift文件来替换RootViewController Objective-c类.

我有一个桥接头文件导入所有在objective-c中导入的头文件

//SwiftForce-Bridging-Header.h 
#import "SFRestAPI.h"
#import "SFRestRequest.h"
Run Code Online (Sandbox Code Playgroud)

我的RooVC.Swift文件如下所示:

import UIKit

class RootVC: UITableViewController,SFRestDelegate {
 ..
..
}
Run Code Online (Sandbox Code Playgroud)

现在,如果我命令+单击SFRestDelegate,它将正确进入协议实现.但是,如果我尝试构建,我得到.." 找不到协议声明SFRestDelegate错误!

SWIFT_CLASS("_TtC10SwiftForce6RootVC")
@interface RootVC : UITableViewController <SFRestDelegate>
@property (nonatomic) NSArray * dataRows;
- (instancetype)initWithStyle:(UITableViewStyle)style OBJC_DESIGNATED_INITIALIZER;
- (void)viewDidLoad;
- (void)didReceiveMemoryWarning;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
@end
Run Code Online (Sandbox Code Playgroud)

感谢任何帮助.您可以从以下 网址下载应用程序来测试它:https ://github.com/rajaraodv/SwiftForce

swift

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

在Objective C中,为什么我的核心数据对象永远不会被释放?

我很难将m个核心数据对象解除分配.我甚至尝试过我能想到的最简单的测试,并且我看到了保留计数,它似乎总是高于我的预期.我还在核心数据对象的dealloc例程上设置了一个断点,它似乎没有被调用(至少除非我专门添加其他版本).

顺便说一句,我肯定有[managedObjectContext setRetainsRegisteredObjects:NO],所以这不是问题.

这是我尝试过的一个不起作用的例子:

MobileObject *obj = [NSEntityDescription insertNewObjectForEntityForName:@"MobileObject" inManagedObjectContext:managedObjectContext];

NSLog(@"Object count after creation %d", [obj retainCount]);

NSError *error;
[managedObjectContext save:&error];

NSLog(@"Object count after saving %d", [obj retainCount]);
Run Code Online (Sandbox Code Playgroud)

每条日志消息都打印出"2".Dealloc永远不会被召唤.我希望save能够释放(或自动释放)对象,因为核心数据应该意识到它不需要保持不变.在这种情况下,如果有两个自动释放(一个来自创建,一个来自保存),则保留计数为2是有意义的,但似乎并非如此.如果我加

[obj release] 
Run Code Online (Sandbox Code Playgroud)

在我测试的最后,dealloc例程将被正确调用,但我很困惑为什么我需要这个版本.

memory-management core-data objective-c

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

核心位置未请求用户权限

我正在测试的应用程序在第一次设备启动时询问用户位置.我已卸载应用程序,删除了构建文件夹,并清除了所有目标,但核心位置从未再次请求权限.它刚刚关闭,必须在用户设置中启用.知道为什么用户选择即使在卸载应用程序后也会保持持久性?非常奇怪的行为,担心它可能会让我拒绝为商店.

core-location ios

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

从字符串中检索图像URL

我正在解析一个xml文件,我可以NSLog解析,但我的问题是我需要从这个"字符串"获取图像url!

<p>
 <a href="http://www.bubblesurprise.com/WPRESS_APP/wp-content/uploads/2012/02/ex43.jpg"><img class="alignnone size-thumbnail wp-image-81" title="ex4" src="http://www.bubblesurprise.com/WPRESS_APP/wp-content/uploads/2012/02/ex43-150x150.jpg" alt="" width="150" height="150" /></a>
 <a href="http://www.bubblesurprise.com/WPRESS_APP/wp-content/uploads/2012/02/ex32.jpg"><img class="alignnone size-thumbnail wp-image-80" title="ex3" src="http://www.bubblesurprise.com/WPRESS_APP/wp-content/uploads/2012/02/ex32-150x150.jpg" alt="" width="150" height="150" /></a>
 <a href="http://www.bubblesurprise.com/WPRESS_APP/wp-content/uploads/2012/02/ex23.jpg"><img class="alignnone size-thumbnail wp-image-79" title="ex2" src="http://www.bubblesurprise.com/WPRESS_APP/wp-content/uploads/2012/02/ex23-150x150.jpg" alt="" width="150" height="150" /></a>
 <a href="http://www.bubblesurprise.com/WPRESS_APP/wp-content/uploads/2012/02/ex12.jpg"><img class="alignnone size-thumbnail wp-image-71" title="ex1" src="http://www.bubblesurprise.com/WPRESS_APP/wp-content/uploads/2012/02/ex12-150x150.jpg" alt="" width="150" height="150" /></a>
 </p>
Run Code Online (Sandbox Code Playgroud)

对不起普通代码:)

我用来提取网址的是这段代码,但它不起作用:

   NSRange start = [item.imageGallery       rangeOfString:@"http://www.bubblesurprise.com/WPRESS_APP/wp-content/uploads/"];
    NSRange end = [item.imageGallery rangeOfString:@"\" "];

    int rangeLength = (int)(end.location - start.location);

    NSString *hrefString = [[NSString alloc] initWithString:[item.imageGallery substringWithRange:NSMakeRange(start.location, rangeLength)]];
    NSLog(@"image url = %@",hrefString);
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios

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

来自不兼容类型'ViewController*const_strong'的'id <MFMailComposeViewControllerDelegate>'

在我的应用程序中,我有一个按钮,当按下时打开一个电子邮件,填写"to"和"subject",但我在这行代码上收到此警告:

mc.mailComposeDelegate = self; 
Run Code Online (Sandbox Code Playgroud)

警告说:

Assigning to 'id<MFMailComposeViewControllerDelegate>'from incompatible type 'ViewController *const_strong'

我该怎么办?请非常清楚,我对xCode不太熟练.

xcode objective-c mfmailcomposeviewcontroller

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

代码签名:指定要求的标识符与应用程序标识符不匹配

我有一个codesign无法完全验证的应用程序,因为它“不满足其指定的要求”。第一次检查返回“在磁盘上有效”,所以没关系。

codesign -dvvvv -r- PATH_TO_APP 告诉我要求,它是:

Identifier=com.foobar.BarBuz-Helper
[...]
designated => anchor apple generic and identifier "com.foobar” and
  (certificate leaf[field.1.2.840.113635.100.6.1.9] /* exists */ or 
  certificate 1[field.1.2.840.113635.100.6.2.6] /* exists */ and 
  certificate leaf[field.1.2.840.113635.100.6.1.13] /* exists */ and 
  certificate leaf[subject.OU] = XXXXXXXXXX)
Run Code Online (Sandbox Code Playgroud)

看起来正确。除了应用程序的标识符实际上不是“com.foobar”而是“com.foobar.BarBuz-Helper”,在我看来这就是它不满足其要求的原因。

Xcode 使用错误的标识符对应用程序进行签名。这是运行的 Xcode 命令:

CodeSign /Users/matthias/[…]-Helper
    setenv CODESIGN_ALLOCATE /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
    Using code signing identity "Developer ID Application: Matthias Bauch"
    /usr/bin/codesign --force --sign 0123456789 --requirements =designated\ =>\ anchor\ apple\ generic\ \ and\ identifier\ \"com.foobar\"\ and\ ((cert\ leaf[field.1.2.840.113635.100.6.1.9]\ exists)\ or\ (\ …
Run Code Online (Sandbox Code Playgroud)

macos xcode code-signing

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

可以从主捆绑中删除文件吗?

我创建了一个sqlite文件并将其添加到我的Xcode项目的mainBundle中.应用程序启动时,此文件将从主程序包复制到文档目录.在将文件复制到文档目录后,是否有可能从mainBundle中删除该文件?

iphone objective-c ipad

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

无法使用标识符将单元格出列

这是导致问题的方法:

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"TableCell";
    TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier 
                                                      forIndexPath:indexPath];

    // Configure the cell...
    int row = [indexPath row];

    Books *book = [myBooks objectAtIndex:row];
    cell.bookName.text = book.bookName;

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

完整日志:

    2014-02-05 23:19:09.458 Books[1425:a0b] *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2903.2/UITableView.m:5251
2014-02-05 23:19:09.471 Books[1425:a0b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier TableCell - must register a nib or a class for the …

objective-c uitableview ios

4
推荐指数
2
解决办法
2万
查看次数