我在使用'initWithFormat'创建字符串时遇到了一些问题.这是我正在使用的代码:
- (void)convertSpeedUnits
{
NSString *speedUnits = [[NSUserDefaults standardUserDefaults] stringForKey:kSpeedUnits];
double speed;
if ([speedUnits isEqualToString:@"Knots"])
{
speed = ms2knots(currentSpeedMS);
}
else if ([speedUnits isEqualToString:@"MPH"])
{
speed = ms2kph(currentSpeedMS);
}
else if ([speedUnits isEqualToString:@"KPH"])
{
speed = ms2mph(currentSpeedMS);
}
NSString *speedLabel = [[NSString alloc] initWithFormat:@"%.2f %s", speed, speedUnits];
currentSpeed.text = speedLabel;
[speedLabel release];
}
Run Code Online (Sandbox Code Playgroud)
我希望speedLabel会是这样的......
'1.12结'或'1.12 MPH'或'1.12 KPH'
但是我得到的是以下内容
'1.12(null)'
我需要一种允许用户从列表中选择选项的方法,我正在考虑使用UIPickerViewa UIAlertView.但是我想知道是否:
UIPickerView在UIAlertView轻松的iOS 5(如果是的话它是由苹果不赞成与将应用程序被拒绝?)任何帮助或建议将非常感谢!
我试图做同样的事情,但在Swift中我遇到了问题:
try/catch在swift中没有相应的块if陈述似乎从未被评估为真实以下是我到目前为止所做的事情:
for searchBarSubview in self.searchBar!.subviews {
if (searchBarSubview.conformsToProtocol(UITextInputTraits)) {
var searchBarTextField = searchBarSubview as UITextField
searchBarTextField.returnKeyType = UIReturnKeyType.Done
}
}
Run Code Online (Sandbox Code Playgroud)
有没有人有任何想法我错了?
我有一个swift项目,我正在MBProgressHUD通过桥接头文件使用.我遇到的问题是,UIView似乎没有被认为是类型,我不知道为什么.
在我的桥接标题中,我有:
#import "MBProgressHUD.h"
Run Code Online (Sandbox Code Playgroud)
我尝试构建时遇到的错误都是一致的:
Cannot find interface declaration for 'UIView', superclass of MBProgressHUD.
Run Code Online (Sandbox Code Playgroud)
我检查了MBProgressHUD文件,我可以看到它肯定会导入以下内容:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
#import "MBProgressHUD.h"
#import "CSNotificationView.h"
Run Code Online (Sandbox Code Playgroud)
还有其他人看过类似的问题吗?如果是,您是否知道问题所在以及如何解决?
我正在尝试将以下plist加载到NSArray中:

这是我用来加载数据的代码:
// Load the data from the plist file
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"MyData" ofType:@"plist"];
NSArray *myArray = [[NSArray alloc] initWithContentsOfFile:filepath];
Run Code Online (Sandbox Code Playgroud)
但是,当我在加载数据后放置一个断点时,我注意到该数组是空的.请有人帮我理解出了什么问题?
我有以下css:
#app-info { float: left; margin: 10px 10px; }
#app-info ul { list-style-type:none; display:block; }
#app-info ul li { padding:2px 0; }
#content { width:650px; float:left; }
#content ul { padding-left: 40px; padding-bottom: 15px; }
#content ul li { padding:5px 0; }
Run Code Online (Sandbox Code Playgroud)
然后我有代码:
<div id="content">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<div id="app-info">
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是内部列表正在被contentid 格式化,但我不想要这个.我只希望app-info课程格式化它.我怎样才能做到这一点?
我正在尝试查询App Store以获取有关给定应用程序的信息,但是我不断收到以下错误.
XMLHttpRequest cannot load https://itunes.apple.com/lookup?id=<some-app-id>.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://www.<some-website>.co.uk' is therefore not allowed access. The response had HTTP status code 501.
Run Code Online (Sandbox Code Playgroud)
我用来执行请求的代码如下.
有谁知道我可能会出错?
var config = {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With',
}
};
$http.get("https://itunes.apple.com/lookup?id=<some-app-id>", config).success(
function(data) {
// I got some data back!
}
);
Run Code Online (Sandbox Code Playgroud) 我正在尝试更新正在显示的选项卡,但它似乎要等到方法结束然后更新.有没有办法让标签显示立即更新?
以下是我遇到此问题的代码示例:
private static void someButtonMethod()
{
Button = new JButton("My Button");
Button(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
tabs.setSelectedIndex(1);
// Do some other things (In my case run a program that takes several seconds to run).
runProgram();
}
});
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将UIImage添加到HTML电子邮件中,但是我遇到了问题.我已经浏览了很多其他帖子,他们都声明我需要将我转换NSData为base64,但是他们所建议的方法似乎不再存在(除非我遗漏了什么?!).
这是我到目前为止的代码:
UIImage *mapImage = [mapViewController convertMapToImage];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(mapImage)];
NSString *base64String = // [imageData base64EncodedString]; --- this method isn't recognised
Run Code Online (Sandbox Code Playgroud)
请有人帮帮我吗?
当我使用核心数据创建实体然后NSManagedObject从中生成子类时,我得到以下输出(在.h中):
@class Foo;
@interface Foo : NSManagedObject
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSSet *otherValues;
@end
Run Code Online (Sandbox Code Playgroud)
但是,在我的.m文件中,我想使用name和otherValues值.通常我会创建几个ivars,然后根据需要为它们添加属性.这样我就可以轻松地在我的.m文件中访问它们.
在这种情况下这样做是否可以接受?将ivars添加到.h(for name和otherValues)会导致持久性和检索对象中的任何异常行为吗?
我使用PHP脚本通过电子邮件发送表单的内容.我希望脚本在发送电子邮件后重定向到另一个html页面,但它似乎无法正常工作.这是我有的:
<?php
// Email to...
$email_to = "xyz@someDomain.co.uk";
// Get the form components
$name = $_GET['name'];
$email_from = $_GET['email'];
$email_subject = $_GET['message-subject'];
$message = $_GET['message'];
// Create the message
$email_message = $message . "\n\n" . $name;
// Create email headers
$headers = 'From: ' . $email_from."\r\n".
'Reply-To: ' . $email_from."\r\n".
'X-Mailer: PHP/' . phpversion().
'Location: Message-Recieved.html';
// Send the email
@mail($email_to, $email_subject, $email_message, $headers);
?>
Run Code Online (Sandbox Code Playgroud)
请有人建议为什么这不起作用?
ios ×3
iphone ×3
objective-c ×3
html ×2
swift ×2
angularjs ×1
base64 ×1
core-data ×1
css ×1
forms ×1
http-get ×1
ios5 ×1
ios9 ×1
ipad ×1
java ×1
javascript ×1
nsarray ×1
nsdata ×1
nsstring ×1
php ×1
plist ×1
swing ×1
tabs ×1
uialertview ×1
uiimage ×1
uipickerview ×1
uisearchbar ×1
uiview ×1
updatepanel ×1