我想在一个点击之外的任何地方解雇UIAlertView.我想在没有任何按钮的情况下显示UIAlertView.
我这里有标准的UIAlertView代码,但如果有可能,我需要输入如何解除它.
有了UITouch吗?使用UITapGestureRecognizer?
谢谢.
编辑:
在viewDidLoad中
alertview初始化,名称为"alert"
if (alert)
{
emptyview = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,480)];
emptyview.backgroundColor = [UIColor clearColor];
[self.view addSubview:emptyview];
[emptyview addSubview:alert];
NSLog (@"emptyview is there!");
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[emptyview addGestureRecognizer:singleTap];
[singleTap release];
}
Run Code Online (Sandbox Code Playgroud)
但是这个空视图根本没有响应,它没有响应handleSingleTap选择器,我重写了一下:
-(void)handleSingleTap:(UITapGestureRecognizer *)sender{
[alert dismissWithClickedButtonIndex:0 animated:YES];
[emptyview removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
我需要这个空视图在显示警报时处于警戒状态然后我可以通过一次点击来解除警报.
我试过了:
if (alert)
{
emptyview = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,480)];
emptyview.backgroundColor = [UIColor clearColor];
[self.view addSubview:emptyview];
[emptyview addSubview:alert];
NSLog (@"emptyview is there!");
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[alert addGestureRecognizer:singleTap];
[singleTap release];
} …Run Code Online (Sandbox Code Playgroud) - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"touchesBegan");
//test
UITouch *touch = [event allTouches] anyObject];
if ([touch tapCount] == 2) {
NSLog (@"tapcount 2");
[self.textview becomeFirstResponder];
}
else if ([touch tapCount] == 1) {
NSLog (@"tapcount 1");
[self.textview becomeFirstResponder];
[self.view performSelector:@selector(select:)];
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesBegan:touches withEvent:event];
NSLog(@"touchesMoved");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"****touchesEnded");
[self.nextResponder touchesEnded: touches withEvent:event];
NSLog(@"****touchesEnded");
[super touchesEnded:touches withEvent:event];
NSLog(@"****touchesEnded");
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesCancelled:touches withEvent:event];
NSLog(@"touchesCancelled");
}
Run Code Online (Sandbox Code Playgroud)
我的问题:
我想在a上点击一次时模拟两次点击UITextView …
我有一个带有UISearchBar的UITableview,它包含日语单词,我想测试它是否可以用日语键盘搜索日语单词.我找不到如何更改iPhone模拟器上的默认键盘.
我有一个nsmutablearray,我在nsarray的for循环中添加了对象.我希望它添加对象,直到它到达NSNotFoundindexOfObject:来自NSArray.该数组位于for循环内,以从每个索引中提取字符串.
我的代码:
NSInteger untilNotFound = NSNotFound;
NSUInteger index = [array indexOfObject:string];
for (index; index < untilNotFound; index ++)
{
[self.mutablearray addObject:[array objectAtIndex: index]];
}
Run Code Online (Sandbox Code Playgroud)
编辑:
for (string in array)
{
NSComparisonResult *result = [string compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)
range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame)
{
NSInteger index;
for (index =[array indexOfObject:string]; (index < [array count] && index < 100 && index!= NSNotFound); index ++)
{
[self.mutablearray addObject:[array objectAtIndex: index]];
}
break;
}
}
Run Code Online (Sandbox Code Playgroud)
编辑.
我之前的代码是有效的,它位于if(result == NSOrderedSame)里面我只是想知道是否有更好,更容易和性能友好的解决方案在它到达NSNotFound之前提取索引:
NSUInteger new …Run Code Online (Sandbox Code Playgroud) 我想知道怎么做.
我看过这个主题,我理解"类型的选择是实现定义的.",但我很想知道如何获得1而不是4.
我的代码:
NSArray *array = //objects here
NSMutableArray *mutarray = [[NSMutableArray alloc] init];
for (NSString *s in array)
{
NSRange ran = [s rangeOfString:@"abc"];
if (ran.location != NSNotFound)
{
int inde = [array indexOfObject:s];
[mutarray setValue:[NSNumber numberWithInt:inde] forKey:s];
}
}
NSLog (@"mutarray: %@", mutarray);
Run Code Online (Sandbox Code Playgroud)
我尝试过NSMutableDictionary,但内容是无序的,所以我更喜欢NSMutableArray有序地存储值和键.但NSLog的输出什么也没有显示,到底是什么?NSMutableDictionary的输出显示了四个发现.
编辑:
我甚至在NSLog前面尝试过这段代码,但没有显示:
[mutarray setValue:@"aha" forKey:@"jaha"];
Run Code Online (Sandbox Code Playgroud)
编辑:伙计们,谢谢你的回答!现在我明白了.但问题是我将数字存储为值和字符串作为键.我有一个无序的NSMutableDictionary.我还没弄明白我应该怎么订购它.我有我使用的代码,但没有正确编写:
NSInteger intSort(id num1, id num2, void *context)
{
int v1 = [num1 intValue];
int v2 = [num2 intValue];
if (v1 < v2)
return NSOrderedAscending;
else if (v1 > v2)
return …Run Code Online (Sandbox Code Playgroud) 我的问题与此类似:
但是我想只为具有细节的单元格显示带有DetailDisclosureButton的accessoryView.
我写了一些代码,但我不知道用哪种方法.
if (totalcount == 0 && totalcount2 == 0)
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
else
{
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
Run Code Online (Sandbox Code Playgroud)
totalcount和totalcount2是两个可变数组的计数,它告诉我单元格是否有详细信息.
如果我的问题不明确,请问我,谢谢.
我已经看到了我的任务的一个答案,但我现在找不到它.我想检测一个字符串是否有空字并且至少包含""或""(两个空格"或多个空格,或者不是.如果没有,我会将其添加到Nsmutablearray.如果是空的或至少一个空格,我希望不要写入mutablearray.
怎么解决这个?
编辑2011年10月12日:
伙计们,谢谢.
我很抱歉,我不清楚我的愿望.我想检查字符串是否为空或包含没有任何字符的空格.我在下面发布了我的答案.
ios ×5
objective-c ×3
uitouch ×2
android ×1
c++ ×1
enums ×1
for-loop ×1
ime ×1
java ×1
keyboard ×1
nsstring ×1
setvalue ×1
simulator ×1
sizeof ×1
tap ×1
uialertview ×1
uitableview ×1
uitextview ×1