我试图在swift中进行IFSCCode验证,但我面临的问题是我无法获取字符串中的前四个字母.
IFSC代码示例:
ABCD0200000
这就是IFSC代码的外观:
我已经在Objective C中为ifs代码验证编写了代码,但我对Swift并不熟悉,所以在Swift中复制相同的问题.
以下是我在Objective C中编写的代码:
- (BOOL)validateIFSCCode:(NSString*)ifsccode {
if (ifsccode.length < 4) {
return FALSE;
}
for (int i = 0; i < 4; i++) {
if (![[NSCharacterSet letterCharacterSet]
characterIsMember:[ifsccode characterAtIndex:i]]) {
return FALSE;
}
}
if (ifsccode.length < 10) {
return FALSE;
}
if ([ifsccode characterAtIndex:4] != '0') {
return FALSE;
} else {
return TRUE;
}
}
Run Code Online (Sandbox Code Playgroud)
在Swift 3中
func validateIfscCode(_ ifscCode : String) -> Bool{
if(ifscCode.characters.count < 4){
return false; …Run Code Online (Sandbox Code Playgroud) 我想在导航栏中添加一个右侧栏按钮项,以便在单击时执行某项功能.
我创建了以下代码来添加正确的条形按钮项,但完成后,条形按钮项不会显示在导航栏中:
-(void)viewDidload{
self.navigationItem.rightBarButtonItem =
[[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(Add:)] autorelease];
}
-(IBAction)Add:(id)sender
{
TAddNewJourney *j=[[TAddNewJourney alloc]init];
[app.navigationController pushViewController:j animated:YES];
[j release];
}
Run Code Online (Sandbox Code Playgroud) 任何人都可以告诉我如何在iPhone模拟器中添加视频,以便我可以测试我正在处理的一些应用程序吗?提前致谢!
如何将导航栏设置为自定义颜色(例如深绿色)?
我知道如何使用以下代码将导航栏更改为绿色和红色等原色:
UINavigationBar *bar = [self.navigationController navigationBar];
[bar setTintColor:[UIColor redColor]];
Run Code Online (Sandbox Code Playgroud)
谢谢.
我有一个地图应用程序.当一个人从当前位置旅行到特定位置时,我想计算该人所覆盖的距离,该人的当前速度,该人的平均速度.
我有一个应用程序,在按钮单击我传递我的服务器api方法,它调用JSON post方法并将数据保存到服务器数据库.这里我将我的手机号码和紧急号码保存到服务器数据库.我的手机号码是字符串格式.在我的手机号码字符串变量中,我的手机号码正在保存,格式为"+ 90-9491491411".我输入+然后编码然后 - 然后编号但是当我发送到服务器数据库时我正在删除 - 并且发送no到数据库,但问题是我的服务器数据库+移动没有进入我正在输入.可能是什么问题.我正在使用POST方法发送请求.这是我的代码
-(void)sendRequest
{
NSString *newstring = txtMobile.text;
mobileValue = [newstring stringByReplacingOccurrencesOfString:@"-" withString:@""];
NSLog(@"%@",mobileValue);
NSString *newString1 = txtemergencyprovider.text;
emergencyNumber = [newString1 stringByReplacingOccurrencesOfString:@"-" withString:@""];
NSLog(@"%@",emergencyNumber);
if ([txtEmail.text isEqualToString:@""])
{
post = [NSString stringWithFormat:@"CommandType=new&ApplicationType=%d&FullName=%@&Mobile=%@&EmergencymobileNumber=%@&Latitude=%f&Longitude=%f&City=%@&MobileModel=Apple",applicationtype,txtFullname.text,mobileValue,emergencyNumber,latitude,longitude,txtCity.text];
NSLog(@"%@",post);
}
else {
post = [NSString stringWithFormat:@"CommandType=new&ApplicationType=%d&FullName=%@&Mobile=%@&EmergencymobileNumber=%@&Latitude=%f&Longitude=%f&City=%@&EmailAddress=%@&MobileModel=Apple",applicationtype,txtFullname.text,mobileValue,emergencyNumber,latitude,longitude,txtCity.text,txtEmail.text];
NSLog(@"%@",post);
}
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSLog(@"%@",postLength);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://myapi?RequestType=NEW"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData]; …Run Code Online (Sandbox Code Playgroud) 我想在ViewController加载时隐藏rightNavigationBarItem.这怎么可能?我试过这段代码,但它无法正常工作.
self.navigationItem.rightBarButtonItem = nil;
Run Code Online (Sandbox Code Playgroud) 我正在iphone中创建一个应用程序,我在我的项目中导入了一个名为CrashReporter.Framework的框架.我已经在我的appdelegate和类中导入了这个框架,名为CrashReportViewController.当我运行应用程序时,它给了我foll错误:
"_OBJC_CLASS_$_PLCrashReport", referenced from:
objc-class-ref-to-PLCrashReport in WordPressAppDelegate.o
objc-class-ref-to-PLCrashReport in CrashReportViewController.o
"_OBJC_CLASS_$_PLCrashReporter", referenced from:
objc-class-ref-to-PLCrashReporter in WordPressAppDelegate.o
objc-class-ref-to-PLCrashReporter in CrashReportViewController.o
Run Code Online (Sandbox Code Playgroud)
可能是什么问题?
我有一个应用程序集成在其中的应用程序.在我的应用程序中,我有两个付费应用程序购买和订阅按钮.当用户点击购买时,它会检查苹果验证并购买产品.
这可以正常工作,但是当购买产品时,我的购买按钮应该变为"完成",当应用程序下次运行时,购买按钮不应该对于该特定产品可见.而应显示"完成"按钮.我的问题是,当购买产品时,显示购买按钮而不是完成按钮.
这是我的代码:
-(void)checkPurchasedItems
{
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
//Then this delegate Function Will be fired
- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
NSLog(@"received restored transactions: %i", queue.transactions.count);
for (SKPaymentTransaction *transaction in queue.transactions)
{
NSString *productID = transaction.payment.productIdentifier;
NSLog(@"%@",productID);
}
}
// called when a transaction has failed
- (void)failedTransaction:(SKPaymentTransaction *)transaction
{
if (transaction.error.code != SKErrorPaymentCancelled)
{
// error!
[self finishTransaction:transaction wasSuccessful:NO];
if (transaction.error.code == SKErrorClientInvalid) {
//[self showAlert:@"In-App Purchase" withMessage:INVALID_CLIENT];
}
else if (transaction.error.code == SKErrorPaymentInvalid) {
//[self showAlert:@"In-App Purchase" withMessage:PAYMENT_INVALID]; …Run Code Online (Sandbox Code Playgroud) 我希望将一个字符串说'Hello'世界转换为php中的ASCII值.但我不想用ord().有没有其他解决方案用于打印ascii值而不使用ord()?
iphone ×8
objective-c ×8
ascii ×1
distance ×1
ios ×1
mapkit ×1
performance ×1
php ×1
swift3 ×1
video ×1