我将以下数据保存为NSString:
{
Key = ID;
Value = {
Content = 268;
Type = Text;
};
},
{
Key = ContractTemplateId;
Value = {
Content = 65;
Type = Text;
};
},
Run Code Online (Sandbox Code Playgroud)
我想将此数据转换为NSDictionary包含键值对的数据.
我首先尝试将其转换NSString为JSON对象,如下所示:
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试:
NSString * test = [json objectForKey:@"ID"];
NSLog(@"TEST IS %@", test);
Run Code Online (Sandbox Code Playgroud)
我收到的价值为NULL.
任何人都可以提出什么问题?
我正在尝试将应用转移到另一个Apple ID.当我这样做时,我收到一个错误,说应用程序无法传输,因为应用程序启用了iCloud.
由于这不是故意的,我试图禁用iCloud并向应用程序提交更新.要做到这一点我:
但是,我仍然无法转移更新的应用程序,仍然会收到iCloud启用的应用程序无法传输的错误.
有谁知道这是否可以修复 - 或者是完全删除应用程序并重新开始的情况?
我有一些文本,我通过NSAttributedString(下面的代码)绘制到一个固定的框架.目前我正在努力将文本大小编码为16.我的问题是,有没有办法计算给定帧文本的最佳拟合大小?
- (void)drawText:(CGContextRef)contextP startX:(float)x startY:(float)
y withText:(NSString *)standString
{
CGContextTranslateCTM(contextP, 0, (bottom-top)*2);
CGContextScaleCTM(contextP, 1.0, -1.0);
CGRect frameText = CGRectMake(1, 0, (right-left)*2, (bottom-top)*2);
NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc] initWithString:standString];
[attrString addAttribute:NSFontAttributeName
value:[UIFont fontWithName:@"Helvetica-Bold" size:16.0]
range:NSMakeRange(0, attrString.length)];
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)(attrString));
struct CGPath * p = CGPathCreateMutable();
CGPathAddRect(p, NULL, frameText);
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0,0), p, NULL);
CTFrameDraw(frame, contextP);
}
Run Code Online (Sandbox Code Playgroud) 我有一个带有许多图像的应用程序.我想检查捆绑中是否存在图像.如果是,我显示它,如果不是我显示替换图像.
下面的代码是我提出的,但它不起作用.谁能发现什么是错的?
谢谢 !
NSString * photo = [NSString stringWithFormat:@"%d.jpg", UniqueID];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:photo];
if([fileManager fileExistsAtPath:path])
{
[image setImage:[UIImage imageNamed:photo]];
}
else {
NSLog(@"Hello");
[image setImage:[UIImage imageNamed:@"iPhoneHD.png"]];
}
Run Code Online (Sandbox Code Playgroud)
编辑 - 更改了以下Simon的帖子,但仍然无法正常工作.其他声明总是触发.
我需要删除所有对象NSMutableArray.我似乎无法通过枚举代码崩溃来做到这一点.
有人可以告诉我使用代码示例执行此操作的最佳方法吗?
我正试图将RelativeLayout中的一个项目放在另一个项目的右侧.在下面的示例中,我希望将","放在说明字段的右侧.但问题是它将逗号放在name字段旁边的第一行.有人可以帮忙吗?
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="10sp">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/name" />
<TextView
android:id="@+id/descriptioncomma"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=", "
android:layout_toRightOf="@id/description" />
Run Code Online (Sandbox Code Playgroud) 我的应用程序中有一个模态视图,显示UIMapView.然后,我将大量注释(超过800个)添加到此地图视图(下面的代码).
问题是当所有引脚加载时,用户被迫等待一分钟左右.一旦所有800个引脚都在地图上,应用程序也会变得迟钝.
任何人都可以建议我如何改进下面的代码?
谢谢.
#import "MapView.h"
#import "MapPlaceObject.h"
@implementation MapView
@synthesize mapViewLink, mapLocations, detail, failedLoad;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)addPins
{
for (MapPlaceObject * info in mapLocations) {
double latitude = info.longitude;
double longitude = info.latitude;
NSString * name = info.name;
NSString * addressline = info.addressOne;
NSString * postcode = info.postCode;
NSString * addresscomma = [addressline stringByAppendingString:@", "];
NSString * address = [addresscomma …Run Code Online (Sandbox Code Playgroud) 在xCode 4.3下运行我的应用程序时,我在上面的主题行中收到警告.
这是违规代码:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:map];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonSystemItemDone target:self action:@selector(removeCurrent)];
map.navigationItem.rightBarButtonItem = rightButton;
[self presentModalViewController:navigationController animated:YES];
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
谢谢 !
我正在使用基于以下线程中的代码的代码来生成视频缩略图:
我的代码如下:
if (selectionType == kUserSelectedMedia) {
NSURL * assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:assetURL options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform=TRUE;
[asset release];
CMTime thumbTime = CMTimeMakeWithSeconds(0,30);
//NSLog(@"Starting Async Queue");
AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
if (result != AVAssetImageGeneratorSucceeded) {
NSLog(@"couldn't generate thumbnail, error:%@", error);
}
//NSLog(@"Updating UI");
selectMediaButton.hidden = YES;
selectedMedia.hidden = NO;
cancelMediaChoiceButton.hidden = NO;
whiteBackgroundMedia.hidden = NO;
//Convert CGImage thumbnail to UIImage.
UIImage …Run Code Online (Sandbox Code Playgroud) 我有以下代码,它分割一串数字(用空格分隔),然后创建一个浮点数组:
//Split the string and then build a float array with the values.
String[] tabOfFloatString = value.split(" ");
int length = tabOfFloatString.length;
System.out.println("Length of float string is" + length);
float[] floatsArray = new float[length];
for (int l=0; l<length; l++) {
float res = Float.parseFloat(tabOfFloatString[l]);
System.out.println("Float is " + res);
floatsArray[l]=res;
}
Run Code Online (Sandbox Code Playgroud)
问题是字符串中的某些值是用科学记数法格式化的 - 例如它们读取-3.04567E-8.
我想要做的是最终得到一个不包含E号的浮点数.
我一直在阅读这个线程,这表明我可以使用BigDecimal,但是无法让它工作 - 这是最好的方法还是我应该尝试别的?如何在Java中将字符串3.0103E-7转换为0.00000030103?
objective-c ×7
iphone ×4
xcode ×3
ios ×2
ipad ×2
sdk ×2
android ×1
apple-id ×1
bigdecimal ×1
core-text ×1
fonts ×1
icloud ×1
java ×1
json ×1
layout ×1
mkmapview ×1
nsdictionary ×1
nsstring ×1
performance ×1
string ×1
thumbnails ×1
video ×1