小编ran*_*dom的帖子

在NSString中添加双引号

我已经阅读了所有内容并且"不起作用.

我正在尝试创建一个如下所示的字符串:

"SomeString"="AnotherString"

这是我必须插入双引号的代码:

NSString *newOutput = [NSString stringWithFormat:@"%@ \" = \" %@", output, [englishDic objectForKey:str]];
Run Code Online (Sandbox Code Playgroud)

它输出的所有内容是:

"RateThisAppDontAsk \" = \" Don't ask again"
Run Code Online (Sandbox Code Playgroud)

我想也许"="导致了问题,但删除仍然给我一个输出:

"RateThisAppDontAsk \"  \" Don't ask again"
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感谢!

formatting objective-c nsstring

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

UIView基于块的动画重绘

我需要设置setAnimationBeginsFromCurrentState一个块.我找不到任何关于如何做的文档或示例.

我需要转换这个:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES]; //The problem
[UIView setAnimationDuration:kKeyboardAnimationDuration];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)

进入一个区块以及设置setAnimationBeginsFromCurrentState属性.

objective-c uiview uiviewanimation objective-c-blocks

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

#if确定.h xcode中的设备类型

我确信这可能非常容易(或者它无法完成),但我似乎无法找到任何东西.

在我的一个.h文件中,我需要确定该应用程序是在iPad还是iPhone上运行.然后相应地更改#define的值.

理想情况下,我会这样看起来像这样:

#if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone

#define deltaX 10.0
#define theda  15.0
#define threshHold 267.0

#endif

#if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad

#define deltaX 78.1
#define theda  67.2
#define threshHold 453.0

#endif
Run Code Online (Sandbox Code Playgroud)

我不知道该使用什么,非常感谢任何帮助.

感谢您的时间!

xcode preprocessor if-statement header-files ios

3
推荐指数
2
解决办法
5859
查看次数

自定义UITableViewCell + UITextField问题

我遇到了一个我似乎无法弄清楚的问题.

我的设置:

  1. 自定义UITableViewCell,其中包含多个文本字段.类似于Apple为联系人中的某人添加新地址时的设置方式.
  2. 具有自定义单元格的表格将显示为模态视图.此表视图还具有其他通用单元格(即不是1中所述的自定义单元格).
  3. 显示的模态视图顶部有一个工具栏,其中包含一个完成按钮.按下完成后,模态视图会将回调发送回其委托并解除.

我遇到的问题:当用户选择UITextField并开始编辑UIKeyboard时(显然是对的?).如果键盘是开放的,用户选择工具栏(如图3所述)的"完成",应用程序崩溃,因为父视图试图解雇模态视图,而键盘打开(含键盘模式视图) .

高级似乎它应该像这样工作:

用户单击工具栏中的"完成" - >检查UIKeyboard是否打开 - >如果打开,则关闭否则忽略模态视图

但事情并非如此简单.

我一直在努力找到一个可行的工作来解决这个问题,并且看起来没有用.

任何建议将非常感激.

编辑

这是崩溃日志:

2011-12-22 16:03:09.021 Renshaw[2308:5f43] bool _WebTryThreadLock(bool), 0xad7a9e0: Tried     to obtain the web lock from a thread other than the main thread or the web thread. This may be     a result of calling to UIKit from a secondary thread. Crashing now...
1   _ZL17_WebTryThreadLockb
2   WebThreadLock
3   -[UITextRangeImpl isEmpty]
4   -[UITextRange(UITextSelectionAdditions) _isCaret]
5   -[UITextSelectionView setCaretBlinks:]
6   -[UIKeyboardImpl setCaretBlinks:]
7   -[UIKeyboardImpl setDelegate:force:]
8   -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:]
9 …
Run Code Online (Sandbox Code Playgroud)

objective-c uitextfield uikeyboard modalviewcontroller ios

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

UISwipeGestureRecognizer未触发

我在IB中有一个UISwipeGestureRecognizer设置链接到我的视图,如下所示:

在此输入图像描述

非常微不足道,完成了一百万次.但是这次它永远不会激发>:|

这是我的方法,应该在用户滑动时调用.

在此输入图像描述

然而,这永远不会被称为.

  • 不,它不会被意外添加到子视图中
  • 是的Pan手势完美无缺.

我有另一个视图设置几乎完全相同,这工作正常.有任何想法吗?

objective-c interface-builder uiview uigesturerecognizer uiswipegesturerecognizer

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

确定何时取消分配UITableViewCell

我在我的应用程序中使用核心数据以及NSFetchedResultsController填充表格.我的数据库有40k +条目,因此表格相当长.每个表格单元格都有一个使用SDWebImage从Web加载的缩略图图像.如果我慢慢滚动,一切都很好,如果我在几秒钟内开始快速滚动,我就会崩溃.

NSZombies没有显示任何有用的东西.

我猜它与SDWebImage网络有关并且从网上加载.方法SDWebImage是在后台加载图像,然后在下载完成后设置下载的图像(罗嗦).我的想法是细胞被释放UITableView,然后SDWebImage尝试在解除分配的细胞上设置图像.因此,如果我可以确定何时UITableViewCell将要解除分配,我可以停止SDWebImage下载过程并希望解决问题.

我试过补充一下

- (void)dealloc {
    NSLog(@"dealloc");
}
Run Code Online (Sandbox Code Playgroud)

当细胞将被解除分配但我从未得到任何东西时捕获.

编辑 我-(void)dealloc在子类UITableViewCell中有我的方法.

编辑 这是我创建单元格的地方/方式

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
 static NSString* inventoryCellID = @"InventoryCustomCellID";

 InventoryCustomCell* cell = (InventoryCustomCell *)[tableView dequeueReusableCellWithIdentifier:inventoryCellID forIndexPath:indexPath];

 [self configureCell:cell atIndexPath:indexPath];

 return cell;
 }


- (void)configureCell:(InventoryCustomCell *)cell atIndexPath:(NSIndexPath *)indexPath {

    [cell formatCellWithProduct:[fetchedResultsController objectAtIndexPath:indexPath] enableAdding:NO];

    cell.openThumbnailButton.tag = indexPath.row;

    [cell.openThumbnailButton addTarget:self action:@selector(presentThumbnailViewWithCell:) forControlEvents:UIControlEventTouchUpInside];
}
Run Code Online (Sandbox Code Playgroud)

在我的自定义单元格中,这是被调用的配置方法:

- (void)formatCellWithProduct:(Product*)product enableAdding:(bool)addingEnabled …
Run Code Online (Sandbox Code Playgroud)

memory-management objective-c uitableview

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

MKMapView没有刷新注释

我有一个MKMapView(显然),它显示了用户周围的住房位置.

我有一个Radius工具,在进行选择时,应根据用户周围的距离添加/删除注释.

我有它添加/删除罚款,但由于某种原因,注释将不会显示,直到我放大或缩小.

这是根据距离添加/删除注释的方法.我尝试了两种不同的方法.

  1. 将新注释添加到数组,然后通过添加到地图[mapView addAnnotations:NSArray].

  2. 添加使用时找到的注释[mapView addAnnotation:MKMapAnnotation];


1.

- (void)updateBasedDistance:(NSNumber *)distance {

    //Setup increment for HUD animation loading
    float hudIncrement = ( 1.0f / [[[[self appDelegate] rssParser]rssItems] count]);

    //Remove all the current annotations from the map
    [self._mapView removeAnnotations:self._mapView.annotations];

    //Hold all the new annotations to add to map
    NSMutableArray *tempAnnotations;

    /* 
     I have an array that holds all the annotations on the map becuase 
     a lot of filtering/searching happens. So for memory reasons it is
     more …
Run Code Online (Sandbox Code Playgroud)

xcode annotations objective-c mkmapview ios

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