小编jhi*_*t00的帖子

UITextField - 防止用户输入非标准字符(如表情符号)

我的应用程序创建并存储EKEvents到标准日历数据库中,但是,我发现如果我使用表情符号作为事件的"注释",则在尝试从日历中读取事件时会导致崩溃.

不想不需要使用表情符号event.notes.我碰巧正在测试,当它让我保存活动时有点震惊.(表情符号甚至出现在日历中)

所以我认为我的问题可以通过2种方式解决,这两种方式都是我无法弄清楚的.

1)我可以禁用或隐藏自定义键盘按钮吗?< - 我更喜欢这个解决方案

在此输入图像描述

2)如果没有,我如何创建一个包含所有标准键盘中所有可能字符的字符集,以确保用户不键入表情符号时进行检查?

我尝试使用一些标准字符集来检查,比如说alphanumericCharacterSet,但是使用它,我不能输入空格.

这是我到目前为止使用的代码,用于检查用户输入的字符:

- (BOOL)textField:(UITextField *)theTextField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (string.length == 0) {
        return YES;
    }

    NSCharacterSet *myCharSet = [NSCharacterSet alphanumericCharacterSet];
    for (int i = 0; i < [string length]; i++) {
        unichar c = [string characterAtIndex:i];
        if ([myCharSet characterIsMember:c]) {
            return YES;
        }
    }

    UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Invalid Input" message:@"Oops! You can't use that character." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; …
Run Code Online (Sandbox Code Playgroud)

uitextfield uikeyboard nscharacterset ios

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

如何将NSDictionary转换为包含NSDictionary的json的NSString?

如何转换NSDictionaryNSString其中包含JSONNSDictionary?我试过但没有成功

//parameters is NSDictionary
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:parameters
                                                       options:0
                                                         error:&error];
Run Code Online (Sandbox Code Playgroud)

ios ios6

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

在Storyboard中使用UITableViewCell时使用alloc和init

我正在使用一个故事板应用simples一个有一个视图UITableViewUITableViewCell那些导航到另一个UIView.

所以必须编写代码来填充表视图上的单元格.

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

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
        NSLog(@"cai no init da cell");
    }

    GPItem *item = [self.items objectAtIndex:indexPath.row];

    cell.textLabel.text = @"Post";
    cell.detailTextLabel.text = item.imageURL;

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

我意识到代码if (cell == nil) { ...永远不会执行所以我真的需要这样做才能使用Storyboard中的单元格吗?

谢谢.

objective-c storyboard uitableview ios

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

UIViewController presentViewController:animated:completion - 需要4到6秒才能启动

我正在构建一个登录模块,其中用户输入的凭据在后端系统中得到验证.我正在使用异步调用来验证凭据,在用户通过身份验证后,我使用该方法进入下一个屏幕presentViewController:animated:completion.问题是,presentViewController启动方法需要花费很长时间才能显示下一个屏幕.我担心我之前的电话会以sendAsynchronousRequest:request queue:queue completionHandler: 某种方式产生副作用.

只是为了确保我说命令presentViewController:animated:completion启动后4-6秒.我是这么说的,因为我正在调试代码并监视调用方法的时刻.

第一:该NSURLConnection方法被称为:

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];

NSOperationQueue *queue = [[NSOperationQueue alloc] init];

[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
Run Code Online (Sandbox Code Playgroud)

第二种:UIViewController方法被称为运行异常时间

UIViewController *firstViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"FirstView"];

[self presentViewController:firstViewController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏.

谢谢,马科斯.

objective-c uiviewcontroller ios

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

同时乘以3个NSDecimalNumber

首先,我正在使用NSDecimalNumbers,因为我正在处理货币.我对十进制数字本身没有任何问题,我想知道是否可以同时乘以3个NSDecimalNumber(s).

换句话说,如果我乘以3个整数,我会简单地说:

int a = 2;
int b = 5;
int c = 7;

int x = a * b * c;
Run Code Online (Sandbox Code Playgroud)

但是,为了乘以NSDecimalNumbers,您必须使用该decimalNumberByMultiplyingBy 方法.

使用这种方法,我必须进行2次计算才能乘以我正在处理的3个NSDecimalNumbers,如下所示:

NSDecimalNumber *d1 = [NSDecimalNumber decimalNumberWithString:@"1.502"];
NSDecimalNumber *d2 = [NSDecimalNumber decimalNumberWithString:@"12.472"];
NSDecimalNumber *d3 = [NSDecimalNumber decimalNumberWithString:@"0.765"];

//Calculation
NSDecimalNumber *initialValue = [d1 decimalNumberByMultiplyingBy:d2];
NSDecimalNumber *finalValue = [initialValue decimalNumberByMultiplyingBy:d3];

//Formatting
NSString *output = [NSString stringWithFormat:@"%@", finalValue];
NSDecimalNumber *n = [NSDecimalNumber decimalNumberWithString:output];

//r is my NSNumberFormatter, which I've configured elsewhere
NSString *s = [r stringFromNumber:n];

NSLog(@"%@",s);
Run Code Online (Sandbox Code Playgroud)

有没有办法同时将所有3个NSDecimalNumbers乘以而不是这种笨重的方式呢?

iphone xcode objective-c nsdecimalnumber ios

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

从滚动禁用UITableview的子视图

(xCode 4.3.2,ARC,Storyboard)像往常一样,我有一个Master/Detail项目,MasterViewController是一个UITableViewController.它顶部有一个导航栏,底部有一个工具栏.我创建了一个以编程方式加载的自定义子视图viewDidLoad.

它加载很好,并且就像我想要的那样在顶部,但是当用户滚动tableview时,子视图也会滚动.我需要子视图"坚持"到底部.

在此输入图像描述

这是我用来添加子视图的代码:

    CGRect totalFrame = CGRectMake(0, 314, 320, 58);
    UIView *totalBG = [[UIView alloc] initWithFrame:totalFrame];
    totalBG.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"totalBG.png"]];
    [self.view addSubview:totalBG];

    CGRect totalLabelFrame = CGRectMake(12, 12, 80, 40);
    totalLabelBG = [[UILabel alloc] initWithFrame:totalLabelFrame];
    totalLabelBG.backgroundColor = [UIColor clearColor];
    totalLabelBG.text = @"Total:";
    [totalLabelBG setFont:[UIFont boldSystemFontOfSize:22]];
    totalLabelBG.userInteractionEnabled = NO;
    totalLabelBG.textColor = [UIColor whiteColor];
    totalLabelBG.shadowColor = [UIColor blackColor];
    totalLabelBG.shadowOffset = CGSizeMake(0, 1);
    [totalBG addSubview:totalLabelBG];
Run Code Online (Sandbox Code Playgroud)

我尝试将userInteractionEnabled设置为NO viewDidLoad并检测触摸,并设置totalLabelBG.center属性,但都没有工作.

我还阅读了许多关于禁用网页浏览滚动的线索,但没有发现任何相关内容.

我发现另一个SOF问题的回复可能有效,也可能不行,但用户没有解释答案."诀窍是在-layoutSubviews中调整"不可滚动"子视图的框架."

xcode scroll subview uitableview

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

Xcode 5 - 应用程序通过验证,图标在通过iTunes安装后显示为灰色

在提交到应用程序商店之前进行最后的测试,我能够存档并验证我的应用程序,然后当我双击我的IPA并且iTunes询问我是否要更换iTunes资料库中的应用程序时,我点击是,同步设备.

  1. 应用程序图标未显示.

  2. 该应用程序保持"灰色"状态.

  3. 如果我点击灰色的应用程序图标,即使同步已完成,名称也会更改为"正在安装...",此时没有任何反应.

几个星期前,我完成了这个过程,完全相同的配置文件,完全相同的设备没有问题.

问题只是第二次开始,当时我不得不"替换"iTunes资料库中的IPA.

我只是在组织者中查看了我的设备,根本没有设备日志.

iphone itunes adhoc ios

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