我有一个奇怪的问题.我有3 UITextField秒和1个UITextView.我可以通过以下方式从一个UITextField移到另一个UITextField:
- (BOOL) textFieldShouldReturn:(UITextField *)textField
{
NSInteger nextTag = textField.tag + 1;
//-- try to find next responde
UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
if (nextResponder)
{
//-- found next responce ,so set it
[nextResponder becomeFirstResponder];
}
else
{
[scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
//-- not found remove keyboard
[textField resignFirstResponder];
return YES;
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
它一切正常,直到它到来UITexView,然后我的光标移动到文本视图的第二行代替第一行文本视图.
文本视图取自IB.
文本视图的代码:
- (void) textViewDidBeginEditing:(UITextView *)textView
{
optionalText.hidden = YES ;
[scrollView setContentOffset:CGPointMake(0, textView.center.y-100) …Run Code Online (Sandbox Code Playgroud) 在UITextField中,我们仅输入数字并限制最多3个数字用于下面的代码
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSUInteger newLength = [textField.text length] + [string length] - range.length;
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS_ONLY] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
while (newLength < CHARACTER_LIMIT) {
return [string isEqualToString:filtered];
}
/* Limits the no of characters to be enter in text field */
return (newLength > CHARACTER_LIMIT ) ? NO : YES;
}
Run Code Online (Sandbox Code Playgroud)
当我长按文本字段(如下图所示)并在两个数字之间输入字符串时,它也允许所有特殊字符和租船人.

我正在创建一个iPhone应用程序,其中我有一个自定义按钮.我通过创建标签并将其添加为子视图来设置按钮标题.现在当按钮突出显示时,我想更改标签文本颜色.
这是我的代码,
UIButton *button1= [UIButton buttonWithType:UIButtonTypeCustom];
[button1 setFrame:CGRectMake(68,162, 635, 101)];
[button1 setImage:[UIImage imageNamed:@"startwithouttext.png"] forState:UIControlStateNormal];
[button1 setImage:[UIImage imageNamed:@"startactivewithouttext.png"] forState:UIControlStateHighlighted];
UILabel *buttonLabel = [[UILabel alloc] initWithFrame:CGRectMake(button1.bounds.origin.x+50, button1.bounds.origin.y+20, button1.bounds.size.width-100, button1.bounds.size.height-40)];
[buttonLabel setFont:[UIFont fontWithName:@"Helvetica" size:28]];
buttonLabel.backgroundColor=[UIColor clearColor];
buttonLabel.textColor=[UIColor colorWithRed:83.0/255.0 green:83.0/255.0 blue:83.0/255.0 alpha:1.0];
buttonLabel.highlightedTextColor=[UIColor whiteColor];
buttonLabel.text = @"Long text string";
[button1 addSubview:buttonLabel];
[button1 bringSubviewToFront:buttonLabel];
[button1 setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[button1 setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[button1 addTarget:self action:@selector(button1clicked:) forControlEvents:
[mainView button1];
Run Code Online (Sandbox Code Playgroud)
当按钮突出显示时,任何身体都可以帮我改变文字颜色吗?
我想在我的应用程序中打开内置的设置应用程序..我想要一些想法来执行它..我怎么能成功?
一些代码..应该更有效.谢谢.Keyur Prajapati
为什么我们不能将两个整数的除法结果存储到float变量中?
int a = 100;
int b =50;
float temp = b/a;
Run Code Online (Sandbox Code Playgroud)
它给出了t = 0!
我也这样做了
int temp = b/a;
Run Code Online (Sandbox Code Playgroud)
它给出了t = 0!
但是当我这样做的时候
float temp = (float)b / (float)a;
Run Code Online (Sandbox Code Playgroud)
它给出了正确的结果.为什么这样 ?
我想重新加载tabbar控制器(UIViewController)中包含的所有视图.搜索后我发现我要应用setNeedsDisplay方法,但我无法在哪里应用它.还欢迎其他任何替代方案
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
.....
.....
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[self customToolbar];
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
-(void)customToolbar
{
//Declared view controllers and their Navigation Controller
.....
//Declared tab bar items
.....
tabBarController = [[GTabBar alloc] initWithTabViewControllers:viewControllersArray tabItems:tabItemsArray initialTab:1];
}
Run Code Online (Sandbox Code Playgroud) 以下是否容易编码?
我有一个tableview,当用户选择一个单元格时,会加载一个详细视图.我希望允许用户通过左右滑动在表格视图中表示项目的项目/细节视图中导航,工作方式与例如iphone的主屏幕相同(例如,在滑动时,一页正在移动关闭屏幕,下一个出现).
我已经看到这在MobileRSS-APP中实现了,所以它是可能的,但我只是很难找到正确的方法.
提前一百万!我仍然试图用可可触摸找到我的脚...
如何在横向模式下隐藏splitviewcontroller的detailView中的导航栏?
在详细视图中,我试过这样
self.navigationController.navigationBar.hidden=YES;
Run Code Online (Sandbox Code Playgroud) 现在我在简单的iPhone应用程序的工作,我已经存储在一定的价值NSMutableArray一样 "{54.399, 196}","{-268.246, 273}".,所以我希望得到54.399的第一indexpath,如何得到这个,请帮助我
提前致谢
下面给出的代码适用于iOS 6,但它不适用于iOS 7.
NSCachedURLResponse cachedURLResponse = [[NSCachedURLResponse alloc] initWithResponse:response data:data userInfo:nil storagePolicy:NSURLCacheStorageAllowed];
[[NSURLCache sharedURLCache] storeCachedResponse:cachedURLResponse forRequest:request];
NSLog(@"Cached response is %@", [[NSURLCache sharedURLCache] cachedResponseForRequest:request]);
Run Code Online (Sandbox Code Playgroud)
在iOS 6中,我获得了缓存的响应数据,但在iOS 7中,它返回null.我使用以下命令在App委托中设置了NSURLCache对象:
NSURLCache *urlCache = [[NSURLCache alloc] initWithMemoryCapacity:2 * 1024 * 1024
diskCapacity:2 * 1024 * 1024
diskPath:nil];
[NSURLCache setSharedURLCache:urlCache];
Run Code Online (Sandbox Code Playgroud)
缓存无法在iOS 7中运行的原因是什么?
iphone ×7
objective-c ×4
ios ×3
ios4 ×2
ipad ×2
arrays ×1
c ×1
ios7 ×1
nsurlcache ×1
swipe ×1
uitableview ×1
uitextfield ×1
uitextview ×1
xcode ×1