我stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding用来将数据传递给php脚本.问题是如果字段中的字符"&"在文本中说:"某人和汽车",只保存文本"某人","&"之后的所有内容都没有.
要创建我使用的字符串[NSString stringWithFormat:],所以我在表单中有5个字段,如果我使用stringbyReplacingOcorrencesOfstring:@"&",它的作用是将整个字符串替换为文本字段中的字符'&',因此我得到错误.
有任何想法吗?
不明白为什么我的NSString数据为空.
我试图从我的应用程序解析json网站上的数字字符串.它成功运行,但是当我试图在我的视图控制器中显示该数字时,它读取为null.我将发布一个示例代码供大家更好地理解.
Handler.m
JsonModel *jsonModel =[[JsonModel alloc]init];
jsonModel.idNumber = [jsonDict valueForKey:@"id"];
nslog(@"%@",jsonModel.idNumber);
Run Code Online (Sandbox Code Playgroud)
JsonModel.h
#import <Foundation/Foundation.h>
@interface JsonModelModel : NSObject
@property (nonatomic, strong) NSString *idNumber;
Run Code Online (Sandbox Code Playgroud)
JsonModel.m
#import "JsonModel.h"
@implementation JsonModel
@synthesize idNumber;
Run Code Online (Sandbox Code Playgroud)
这部分工作成功,我能够解析必要的数据并NSLog证明它.但是,这就出现了问题.PS idNumber是NSString.
ViewController.m
-(void)method{
JsonModel *jsonModel =[[JsonModel alloc]init];
NSLog(@"%@",jsonModel.idNumber);
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,NSLog显示为null.即使首先解析了json数据,然后调用视图控制器中的方法.我必须缺少一些小细节.如果有人帮我搞清楚,我会很感激.
我已经四处搜索并找到了几个与此类似的问题,但不完全相同,我无法得到这些答案中给出的示例代码.我承认这很可能是因为我对Objective-C的无知阻碍了.我的情况是这样的:
我有一个来自文本文件的NSString,其中包含各种字符.字符串的长度可以根据文本文件中的内容而变化.我需要创建一个数组,给出字符串中的每个字符.
我已经尝试了5种不同的方法解决问题(其中三种来自本网站的答案),但我为此做的每一项努力都导致a)我无法追踪的分段错误,b)数组保持为NULL同时给出编译器警告,或c)数组保持NULL而没有编译器警告.如果它重要,我正在使用:gcc -framework Foundation -std = c99 TestCode.m -o TestProgram
对不起,这里没有具体的代码,因为我已经删除了所有失败的努力.我想有一个原因,你不应该尝试学习一门编程语言,同时尝试学习你正在应用该语言的新主题:)
有人会这么有帮助,给我一些片段与这里合作吗?
我正在构建一个iOS社交客户端,在"撰写"视图中,我有一个UITextView用户输入文本的位置.我想使用ReactiveCocoa绑定text的UITextView对NSString数据模型的,遵循MVVM.
但是,我遇到了几个问题,都与一件事有关:RACObserve当以UITextView编程方式更改文本时,不会调用块.
(举个例子:我更改文本成属性串突出#哈希标签,@使用者名称等,但是当视图以编程方式改变了这种属性串还没有生成.)
在我以前的关于这个主题的问题,我得到了我应该绑定的TextView到模型中一些有用的建议-反之亦然-但我应该如何与活性可可的当前版本做这我不清楚.我设法找到的示例代码调用了现在已弃用的API.
什么是绑定的适当方法rac_textSignal的UITextView一个NSString(反之亦然),这样当的内容,我可以可靠地调用的代码块UITextView被改变(无论是编程或由用户)?
我看着苹果基准上NSRegularExpression,并理解,为了看到如果字符串是西里尔我应该使用\p{script=cyrillic}.但是,我无法在参考指南或SO 中的答案中找到如何完成此操作的实际示例.我理想的目标是:
if (string contains \p{script=cyrillic}){
return YES;
}
else {
return NO;
}
Run Code Online (Sandbox Code Playgroud) 我正在检查一个字符串是否在一个数组中连续出现两次.这段代码似乎不起作用,因为它只打印出整个数组.我错过了什么?
NSString *nameString =
[NSString stringWithContentsOfFile:@"/usr/share/dict/words"
encoding:NSUTF8StringEncoding
error:NULL];
NSArray *names = [nameString componentsSeparatedByString:@"\n"];
//Save last item
NSMutableString *lastOne = [NSMutableString stringWithCapacity:20];
// Go through the array one string at a time
for (NSString *n in names) {
if ([n compare:lastOne options:NSCaseInsensitiveSearch]) {
NSLog(@"%@", n);
}
[lastOne setString:n];
}
Run Code Online (Sandbox Code Playgroud) 我试图在productdetailview对象中获取标签的值,并将其写在编辑产品对象上的文本字段中.谁能告诉我这是什么问题?
谢谢.
编辑:下面添加了更多代码来解决标签到文本字段问题.
product.h
#import <Foundation/Foundation.h>
@interface Product : NSObject
@property (strong, nonatomic) NSString *name;
@property (strong, nonatomic) NSString *description;
@property (strong, nonatomic) NSString *product_id;
@property (strong, nonatomic) NSString *model;
@property (strong, nonatomic) NSString *sku;
@property (strong, nonatomic) NSString *quantity;
@property (strong, nonatomic) NSURL *imageUrl;
@property (strong, nonatomic) NSString *price;
@property (strong, nonatomic) NSString *weight;
@property (strong, nonatomic) NSString *length;
@property (strong, nonatomic) NSString *width;
@property (strong, nonatomic) NSString *height;
@property (strong, nonatomic) NSString *status;
@property (strong, nonatomic) NSString *date_added; …Run Code Online (Sandbox Code Playgroud) 我有以下代码
NSString * myStr = [[NSString alloc] initWithFormat:@""];
Run Code Online (Sandbox Code Playgroud)
但在Xcode中,我有一个带有"预期表达式"的红色感叹号.
我解决了以下问题:
[NSString stringWithFormat:@"Number is not from 1 to 6. randomNumber is %d", randomNumber]
Run Code Online (Sandbox Code Playgroud)
但我想知道问题是什么.
图片
http://imgur.com/iICMhYc&S7QwhFT#1
谢谢
这里有一些工作代码,它在完成时为待办事项添加一个复选标记:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"ListPrototypeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
XYZToDoItem *toDoItem = [self.toDoItems objectAtIndex:indexPath.row];
cell.textLabel.text = toDoItem.itemName;
if (toDoItem.completed) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
} return cell;
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是删除复选标记代码和类似的东西(它的基本逻辑):
if (toDoItem.completed) {
cellIdentifier.textLabel (NSAttributedString Strikethrough = YES)
} else {
cellIdentifier.textLabel (NSAttributedString Strikethrough = NO)
} return cell;
Run Code Online (Sandbox Code Playgroud)
我也试图改变NSString,以NSAttributedString和NSMutableAttributedString基于我已经看到了一些其他的问题和答案,如这一个是这样的:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary* …Run Code Online (Sandbox Code Playgroud) 我有一个NSString看起来像:
{
"name": "anEvent",
"args": [
{
"ct": "Un",
"someUUID": "D7EC06DE-98D3-436F-A657-FB043567FB67",
"userName": "Joe Smith",
"long": "-139.724302",
"lat": "39.402768"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到内在的部分
{
"ct": "Un",
"someUUID": "D7EC06DE-98D3-436F-A657-FB04383CFB67",
"userName": "Joe Smith",
"long": "-139.724305",
"lat": "39.402768"
}
Run Code Online (Sandbox Code Playgroud)
变成了NSDictionary?
谢谢.
nsstring ×10
objective-c ×8
ios ×7
cocoa ×1
cocoa-touch ×1
iphone ×1
json ×1
jsonmodel ×1
nsarray ×1
regex ×1
uilabel ×1
uitextfield ×1
uitextview ×1
xcode ×1