小编Vik*_*ica的帖子

Objective-C 双、长计算

我正在尝试计算一个 long 值除以一个整数,以给出我期望的 double 值,尽管我得到的结果是 0。我正在使用的代码......

double daysByYear = daysSinceBirthdayToService/365;
NSLog(@"%d", daysByYear);
Run Code Online (Sandbox Code Playgroud)

在这段代码中, daysSinceBirthdayToService 变量是一个 Long Double,可以使用以下代码进行 NSLogged (long)daysSinceBirthdayToService

它在头文件中声明为

@property (nonatomic) NSInteger daysSinceBirthdayToService;
Run Code Online (Sandbox Code Playgroud)

谁能帮我解决这个问题,谢谢!

cocoa-touch objective-c ios

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

我可以减少重复声明中的代码吗?

有没有办法减少Obj-C中重复声明的代码?

例如:

我有

    localNotification.fireDate = self.dueDate;
    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    localNotification.alertBody = self.text;
    localNotification.soundName = UILocalNotificationDefaultSoundName;
Run Code Online (Sandbox Code Playgroud)

它可以简化为这样的东西吗?

 localNotification
    .fireDate = self.dueDate;
    .timeZone = [NSTimeZone defaultTimeZone];
    .alertBody = self.text;
    .soundName = UILocalNotificationDefaultSoundName;
Run Code Online (Sandbox Code Playgroud)

谢谢!

cocoa-touch objective-c ios

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

NSDate 中的时间/日期显示就像 iOS 中的消息和邮件应用程序一样

我正在构建一个应用程序,要求我显示时间和日期,即星期日(如果对象是在 24 小时之前创建的)等。就像 iOS 中的消息和邮件应用程序会显示 24 小时的时间,然后将其更改为显示“星期一”等日期,星期二......”。我正在寻找是否可以找到任何完全像这样的框架,或者我是否必须为此编写代码?

cocoa-touch nsdate ios

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

如何在iOS 7中更改UISearchBar

我正在为iOS 7创建一个应用程序,我需要在我的UITableView中添加UISearchBar.搜索功能工作正常,我的问题是我试图使用下面的代码自定义我的搜索栏UI,以实现我的输出如下截图:

在此输入图像描述

这是我的代码:

searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(40, 29, 266, 27)];
searchBar.delegate = self;
searchBar.barTintColor = [UIColor clearColor];
[[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];
[[UISearchBar appearance] setSearchFieldBackgroundImage:[UIImage imageNamed:@"search-bar.png"]forState:UIControlStateNormal];

NSDictionary *attributes =
[NSDictionary dictionaryWithObjectsAndKeys:
 [UIColor whiteColor], UITextAttributeTextColor,
 [UIFont fontWithName:@"HPSimplifiedW01-Regular" size:14.0f], UITextAttributeFont,
 nil];
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil]
 setTitleTextAttributes:attributes forState:UIControlStateNormal];
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil]
 setTitleTextAttributes:attributes forState:UIControlStateHighlighted];

for (UIView *subView in searchBar.subviews)
{
    for (UIView *secondLevelSubview in subView.subviews){
        if ([secondLevelSubview isKindOfClass:[UITextField class]])
        {
            UITextField *searchBarTextField = (UITextField *)secondLevelSubview;
            searchBarTextField.clearButtonMode = UITextFieldViewModeNever;
            //set font color …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch objective-c uisearchbar ios

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

为什么self.splitViewController == nil?

我使用Xcode 6的Master Detail Application模板创建了一个新的iOS 8项目.我没有以任何方式更改代码.

在设置断点DetailViewController.m并检查self.splitViewController属性时,如下面的屏幕截图所示,它将返回nil.

在此输入图像描述

这是为什么?

根据Apple UISplitViewController 文档,self.splitViewController应该返回最近的SplitViewController:

如果接收器或其祖先之一是拆分视图控制器的子级,则此属性包含拥有的拆分视图控制器.如果视图控制器未嵌入拆分视图控制器中,则此属性为nil.

objective-c uiviewcontroller uisplitviewcontroller ios ios8

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

删除/停止dispatch_async iOS

我创建了一个dispatch_async来将数据下载到Web服务.

我使用possibilida中的按钮创建了一个警报,以取消/阻止下载.

我的问题是:

如何删除/停止dispatch_async?

这是我的发送:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
    doStuff();
}
Run Code Online (Sandbox Code Playgroud)

objective-c grand-central-dispatch ios swift

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

使用Swift格式化日期

我正在尝试使用Date Formatter将字符串转换为日期.

var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd’T’HH:mm:ss’Z’"
var AvailabletoDateTime = dateFormatter.dateFromString("2015-07-16’T’08:00:00’Z’")
Run Code Online (Sandbox Code Playgroud)

但是,AvailabletoDateTime正在返回零.有人可以帮助我,如果我想念Anything Here,请告诉我.

nsdateformatter swift

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

调用方法的错误做法?

我对良好或不良做法有疑问。

我创建了一个函数,该函数将生成一个随机数。如果随机数等于先前的随机数,则应生成一个新数。所以我的问题是。从方法中调用相同的方法是不好的做法吗?

func getRandomNumber(){ //<-- Method name
    let randomNumber = Int.random(in: 0..<allPlayers.count)

    if lastRoundNumber == randomNumber{
        getRandomNumber() //<-- Like this
    }
    print(randomNumber)
}
Run Code Online (Sandbox Code Playgroud)

还是我应该这样做?如果是,怎么办?

因此,像我在上面的代码中所做的那样,从当前方法中调用相同的方法是不好的做法吗?提前致谢。

如果是,为什么不好?以及如何获得更好的代码?

swift

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

如何迭代图像的列?

我想像这样转换图像,为django中的图片添加效果,如此处所述.

考拉挥了挥手

我决定将它作为一个伟大的django -imagekit/photologue 的过程来实现

我对PIL的了解不是很好,所以我的问题是

如何通过PIL中的正弦偏移来打算像素列?

任何提示(代码,lins,一般想法)都受到欢迎

django photologue imagekit python-imaging-library django-imagekit

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

如何使用双引号将NSString初始化为文本

我想初始化NSString是双haoutes的"hai"..它可能吗?有什么帮助吗?但是NSString*str = @"hai"; 我想在没有直接初始化的情况下将其转换为"hai"?有什么帮助吗?

cocoa-touch objective-c ios

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