小编use*_*804的帖子

比较目标C中的float和double数据类型

当在iPhone应用程序中使用double或float数据类型时,我遇到了"> ="和"<="比较的问题,因为当为变量分配一个带有一个小数位的数字时,例如4.2,浮点数或双精度数用于比较实际上可能有一个值,如4.1999998092651367.由于这种差异,诸如"> = 4.2"之类的比较是错误的而不是真实的.我该如何避免这个问题?

c iphone floating-point double objective-c

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

使用QLPreviewController显示Documents文件夹中的文件

我非常感谢这里使用的教程QLPreviewController .

我正在尝试将此代码实现到我的应用程序中,并修改了从应用程序的Documents文件夹而不是Resources文件夹中显示文件(以便用户可以使用iTunes文件共享来管理文档).但是,这样做我遇到了" EXC_BAD_ACCESS"错误.

我在Documents文件夹中创建一个文件数组来生成tableview列表:

- (void)viewDidAppear:(BOOL)animated {

[super viewDidAppear:animated];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsPath = [paths objectAtIndex:0];

arrayOfDocuments = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsPath error:NULL];
}
Run Code Online (Sandbox Code Playgroud)

以这种方式显示Documents文件夹中的文件列表没有问题.

使用QuickLook从列表中显示所选文件的代码是:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{  
// When user taps a row, create the preview controller
QLPreviewController *previewer = [[[QLPreviewController alloc] init] autorelease];

// Set data source
[previewer setDataSource:self];

    // Which item to preview
[previewer setCurrentPreviewItemIndex:indexPath.row];

// Push new viewcontroller, previewing the document
[[self navigationController] pushViewController:previewer …
Run Code Online (Sandbox Code Playgroud)

iphone qlpreviewcontroller

5
推荐指数
0
解决办法
2675
查看次数

以编程方式创建的UITextView不再使用iOS 9滚动

以下代码以编程方式创建一个文本视图,该文本视图在文本超出设备屏幕高度时滚动.代码在iOS 7和iOS 8中没有问题.但是,文本字段不再使用相同代码的iOS 9滚动.通过几个小时的尝试找到修复,这个问题非常令人沮丧,所以我非常感谢任何帮助.提前致谢.这是代码:

- (void)createTextView
Run Code Online (Sandbox Code Playgroud)

{

//1. Create the text storage that backs the editor.
NSDictionary *attrs = @{NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleBody]};
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:notesAndReference attributes:attrs];
_textStorage = [[SyntaxHighlightTextStorage alloc] init];
[_textStorage appendAttributedString:attrString];

CGRect newTextViewRect = self.view.bounds;

//2. Create the layout manager.
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];

//3. Create a text container.
CGSize containerSize = CGSizeMake(newTextViewRect.size.width, CGFLOAT_MAX);
NSTextContainer *container = [[NSTextContainer alloc] initWithSize:containerSize];
container.widthTracksTextView = YES;
[layoutManager addTextContainer:container];
[_textStorage addLayoutManager:layoutManager];

//4. Create a UITextView.
textView = …
Run Code Online (Sandbox Code Playgroud)

objective-c uitextview ios ios9

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

使用stringWithFormat在iPhone的标签区域中显示数值

我是Objective C和iPhone SDK的新手,我正在尝试将以下内容作为在标签区域中显示数字结果的简单示例:

label.text = [NSString stringWithFormat: @"%d", 55];
Run Code Online (Sandbox Code Playgroud)

上面的代码在标签区域显示数字"55".但是,以下代码导致显示"0"(在header文件中将calculateResult声明为双变量类型):

calculationResult = 55;
label.text = [NSString stringWithFormat: @"%d", calculationResult];
Run Code Online (Sandbox Code Playgroud)

任何帮助深表感谢.

objective-c stringwithformat iphone-sdk-3.0

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

Custom cell in UITableView not working properly in iOS 13 Dark Mode

I have used, since 2011, Objective-C code for my medical application, which basically has 5 tabs with associated UITableViews, 3 of which use custom cells. Initially with using Dark Mode I found that the custom cells did not change to Dark Mode automatically. Instead, I needed to implement the code below to test for Dark Mode and make cell text and background changes accordingly.

The problem is that the Dark Mode changes do not occur for empty cells in the …

objective-c cell uitableview ios13 ios-darkmode

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