小编Tam*_*gel的帖子

如何检查iOS或macOS上的活动Internet连接?

我想查看我是否在iOS上使用Cocoa Touch库或使用Cocoa库在macOS 上建立了Internet连接.

我想出了一个方法,使用一个NSURL.我这样做的方式似乎有点不可靠(因为即使谷歌有一天会失败并依赖第三方看起来很糟糕),而且如果谷歌没有回应,我可以查看其他网站的回复,在我的应用程序中看起来似乎很浪费并且不必要的开销

- (BOOL) connectedToInternet
{
    NSString *URLString = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com"]];
    return ( URLString != NULL ) ? YES : NO;
}
Run Code Online (Sandbox Code Playgroud)

我做得不好,(更不用说stringWithContentsOfURL在iOS 3.0和macOS 10.4中被弃用)如果是这样,有什么更好的方法来实现这一目标?

macos cocoa cocoa-touch reachability ios

1309
推荐指数
34
解决办法
44万
查看次数

iOS - 在UITextField外部触摸时关闭键盘

我想知道如何在用户触摸外面时使键盘消失UITextField.

cocoa-touch uitextfield uikit ios

451
推荐指数
16
解决办法
24万
查看次数

如何在Swift 4中使用字符串切片下标?

我有以下用Swift 3编写的简单代码:

let str = "Hello, playground"
let index = str.index(of: ",")!
let newStr = str.substring(to: index)
Run Code Online (Sandbox Code Playgroud)

从Xcode 9 beta 5,我得到以下警告:

' substring(to:)'已被弃用:请使用String带有'partial range from'运算符的切片下标.

如何在Swift 4中使用具有部分范围的切片下标

swift swift4

286
推荐指数
11
解决办法
12万
查看次数

如何将Swift代码导入Objective-C?

我在Swift中编写了一个库,但我无法将其导入到用Objective-C编写的当前项目中.

有没有办法导入它?

#import "SCLAlertView.swift" - 'SCLAlertView.swift' file not found
Run Code Online (Sandbox Code Playgroud)

import objective-c swift

271
推荐指数
11
解决办法
17万
查看次数

什么是Objective-C中的isEqualToString的Swift等价物?

我正在尝试运行以下代码:

import UIKit

class LoginViewController: UIViewController {

@IBOutlet var username : UITextField = UITextField()
@IBOutlet var password : UITextField = UITextField()

@IBAction func loginButton(sender : AnyObject) {

    if username .isEqual("") || password.isEqual(""))
    {
        println("Sign in failed. Empty character")
    }
}
Run Code Online (Sandbox Code Playgroud)

我之前的代码是在Objective-C中,它运行良好:

 if([[self.username text] isEqualToString: @""] ||
    [[self.password text] isEqualToString: @""] ) {
Run Code Online (Sandbox Code Playgroud)

我假设我不能isEqualToString在Swift中使用.任何帮助,将不胜感激.

string swift

259
推荐指数
5
解决办法
22万
查看次数

如何删除Xcode 8中的派生数据?

项目页面似乎从Xcode 8中消失了.我使用此页面删除了派生数据.

知道如何从Xcode 8中删除派生数据?

xcode xcode8

258
推荐指数
12
解决办法
19万
查看次数

设置自定义UITableViewCells高度

我正在使用自定义UITableViewCell,它有一些标签,按钮和图像视图可供显示.单元格中有一个标签,其文本是NSString对象,字符串的长度可以是可变的.由于这一点,我无法设置恒定的高度到细胞中UITableViewheightForCellAtIndex方法.细胞的高度取决于这可以使用被确定标签的高度NSStringsizeWithFont方法.我尝试过使用它,但看起来我在某个地方出错了.怎么修好?

这是用于初始化单元格的代码.

if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier])
{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    UIImage *image = [UIImage imageNamed:@"dot.png"];
    imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(45.0,10.0,10,10);

    headingTxt = [[UILabel alloc] initWithFrame:   CGRectMake(60.0,0.0,150.0,post_hdg_ht)];
    [headingTxt setContentMode: UIViewContentModeCenter];
    headingTxt.text = postData.user_f_name;
    headingTxt.font = [UIFont boldSystemFontOfSize:13];
    headingTxt.textAlignment = UITextAlignmentLeft;
    headingTxt.textColor = [UIColor blackColor];

    dateTxt = [[UILabel alloc] initWithFrame:CGRectMake(55.0,23.0,150.0,post_date_ht)];
    dateTxt.text = postData.created_dtm;
    dateTxt.font = [UIFont italicSystemFontOfSize:11];
    dateTxt.textAlignment = UITextAlignmentLeft;
    dateTxt.textColor = [UIColor grayColor];

    NSString * text1 …
Run Code Online (Sandbox Code Playgroud)

objective-c row-height uitableview ios

221
推荐指数
8
解决办法
27万
查看次数

如何在NSAttributedString中创建可单击的链接?

在a中点击超链接是微不足道的UITextView.您只需在IB中的视图上设置"检测链接"复选框,它就会检测HTTP链接并将其转换为超链接.

但是,这仍然意味着用户看到的是"原始"链接.RTF文件和HTML都允许您设置一个用户可读的字符串,其中包含一个"后面"的链接.

可以很容易地将属性文本安装到文本视图中(或者,UILabel或者UITextField就此而言).但是,当该属性文本包含链接时,它不可单击.

有没有办法让用户可读的文本可以点击UITextView,UILabelUITextField

标记在SO上是不同的,但这是一般的想法.我想要的是这样的文字:

此变形是使用Face Dancer生成的,单击可在应用商店中查看.

我唯一能得到的是:

使用Face Dancer生成此变形,单击http://example.com/facedancer以在应用商店中查看.

objective-c hyperlink uitextview nsattributedstring ios

186
推荐指数
13
解决办法
19万
查看次数

如何模拟地图应用中的底部工作表?

任何人都可以告诉我如何在iOS 10中的新地图应用程序中模仿底页?

在Android中,您可以使用BottomSheet模仿此行为的模式,但我找不到类似iOS的内容.

这是一个带有内容插入的简单滚动视图,以便搜索栏位于底部吗?

我对iOS编程很新,所以如果有人可以帮助我创建这个布局,那将非常感激.

这就是我所说的"底页":

地图中折叠的底部工作表的屏幕截图

地图中展开的底部工作表的屏幕截图

uiscrollview uiview mapkit ios swift

179
推荐指数
6
解决办法
7万
查看次数

Objective-C中的"无法识别的选择器发送到实例"错误

我创建了一个按钮,并为其添加了一个动作,但是一旦调用它,我就收到了这个错误:

-[NSCFDictionary numberButtonClick:]: unrecognized selector sent to instance
 0x3d03ac0 2010-03-16 22:23:58.811
 Money[8056:207] *** Terminating app
 due to uncaught exception
 'NSInvalidArgumentException', reason:'*** -[NSCFDictionary numberButtonClick:]:  unrecognized selector sent to instance 0x3d03ac0'
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        UIButton *numberButton = [UIButton buttonWithType:UIButtonTypeCustom];        
        numberButton.frame = CGRectMake(10, 435, 46, 38);
        [numberButton setImage:[UIImage imageNamed:@"one.png"] forState:UIControlStateNormal];
        [numberButton addTarget:self action:@selector(numberButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview: numberButton]; 
    }
return self;
}

-(IBAction)numberButtonClick:(id)sender{
    NSLog(@"---");
}
Run Code Online (Sandbox Code Playgroud)

objective-c selector unrecognized-selector

151
推荐指数
10
解决办法
39万
查看次数