私が取り組んでいるアプリでは、ユーザーはさまざまなボタンを使用して、テキストを読んだりテキストを作成したりできます。私の問題は、テキストを読むための画面で、ユーザーがテキストを書くために画面で使用される UITextView ボックス内をタップすると、キーボードが表示されることです。この場合の UITextView はself.textView
; ステートメント内にキーボード通知と keyboardWillShow メソッドを配置し、読み取りテキスト メソッドの先頭でif(self.textView)
呼び出し[self.textView removeFromSuperView]
て設定するようにしましたが、設定されているスペースをタップするとキーボードが表示されます(ちなみに、プログラムで、 IB を使用しない)。self.textView = nil;
self.textView
私は何を間違っていますか?
編集: 答えてくれてありがとう、男と女、しかしそれでも、歌の中の猫のように、そのくそキーボードが戻ってきます....これが私のコードです。できれば、その長さを許してください。何かおかしなことをしてしまったら、それがどこにあるのかわからないので、何を省けばよいのかわからないのです。
ここにありviewDidLoad
ます。
-(void)viewDidLoad {
[super viewDidLoad];
self.textView.editable=NO;
self.textView.userInteractionEnabled = NO;
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(previousHaiku)];
swipeRight.numberOfTouchesRequired = 1;
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(nextHaiku)];
swipeLeft.numberOfTouchesRequired = 1;
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"gayHaiku.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path])
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"gayHaiku" ofType:@"plist"];
[fileManager copyItemAtPath:bundle toPath: path error:&error];
}
self.gayHaiku = [[NSMutableArray alloc] initWithContentsOfFile: path];
[self nextHaiku];
}
これが で呼び出さnextHaiku
れた最後のviewDidLoad
メソッドです。これは読み取りメソッドです。
-(void)nextHaiku
{
[self.view.layer removeAllAnimations];
[self.bar removeFromSuperview];
self.textToSave=@"";
self.haiku_text.text=@"";
[self.view viewWithTag:1].hidden = NO;
[self.view viewWithTag:3].hidden = NO;
int indexOfHaiku;
NSMutableArray *arrayOfHaikuSeen;
NSString *cat;
if (!self.selectedCategory) cat = @"Derfner";
else cat = self.selectedCategory;
NSArray *filteredArray;
if (cat==@"all")
{
filteredArray = self.gayHaiku;
indexOfHaiku = self.indxAll;
arrayOfHaikuSeen = self.theseAreDoneAll;
}
else
{
indexOfHaiku = (cat==@"user")?self.indxU:self.indxD;
arrayOfHaikuSeen = (cat==@"user")?self.theseAreDoneU:self.theseAreDoneD;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"category == %@", cat];
filteredArray = [self.gayHaiku filteredArrayUsingPredicate:predicate];
}
int array_tot = [filteredArray count];
int sortingHat;
NSString *txt;
if (array_tot > 0)
{
if (indexOfHaiku == arrayOfHaikuSeen.count)
{
while (true)
{
sortingHat = (arc4random() % array_tot);
if (![arrayOfHaikuSeen containsObject:[filteredArray objectAtIndex:sortingHat]]) break;
}
txt = [[filteredArray objectAtIndex:sortingHat] valueForKey:@"quote"];
if (!arrayOfHaikuSeen || arrayOfHaikuSeen.count==array_tot)
{
arrayOfHaikuSeen = [[NSMutableArray alloc] init];
}
[arrayOfHaikuSeen addObject:[filteredArray objectAtIndex:sortingHat]];
indexOfHaiku = arrayOfHaikuSeen.count;
if (arrayOfHaikuSeen.count==filteredArray.count)
{
[arrayOfHaikuSeen removeAllObjects];
indexOfHaiku=0;
}
}
else
{
txt = [[arrayOfHaikuSeen objectAtIndex:indexOfHaiku] valueForKey:@"quote"];
indexOfHaiku += 1;
}
}
//Need to test to make sure it starts over once all 110 haiku have been seen.
CGSize dimensions = CGSizeMake(320, 400);
CGSize xySize = [txt sizeWithFont:[UIFont fontWithName:@"Helvetica" size:14.0] constrainedToSize:dimensions lineBreakMode:0];
self.haiku_text = [[UITextView alloc] initWithFrame:CGRectMake((320/2)-(xySize.width/2),200,320,200)];
self.haiku_text.font = [UIFont fontWithName:@"Helvetica Neue" size:14];
self.haiku_text.backgroundColor = [UIColor clearColor];
self.haiku_text.text=txt;
CATransition *transition = [CATransition animation];
transition.duration = 0.25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype =kCATransitionFromRight;
transition.delegate = self;
[self.view.layer addAnimation:transition forKey:nil];
[self.view addSubview:self.haiku_text];
if (cat==@"user")
{
self.theseAreDoneU = arrayOfHaikuSeen;
self.indxU = indexOfHaiku;
}
else if (cat==@"all")
{
self.theseAreDoneAll = arrayOfHaikuSeen;
self.indxAll = indexOfHaiku;
}
else
{
self.theseAreDoneD = arrayOfHaikuSeen;
self.indxD = indexOfHaiku;
}
}
で、書き方はこちら。
-(void)userWritesHaiku
//Set up the screen.
[self clearScreen];
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 60, 280, 150)];
self.textView.delegate = self;
self.textView.returnKeyType = UIReturnKeyDefault;
self.textView.keyboardType = UIKeyboardTypeDefault;
self.textView.font = [UIFont fontWithName:@"Helvetica Neue" size:14];
self.textView.scrollEnabled = YES;
self.textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
self.textView.userInteractionEnabled = YES;
self.textView.editable=YES;
self.textView.backgroundColor = [UIColor colorWithRed:217 green:147 blue:182 alpha:.5];
[self.view addSubview: self.textView];
[self loadNavBar:@"Compose"];
[self addLeftButton:@"Instructions" callingMethod:@"haikuInstructions"];
//If you've added text before calling haikuInstructions, when you return from haikuInstructions the textView window with the different background color AND the keyboard.
[self addRightButton:@"Done" callingMethod:@"userFinishedWritingHaiku"];
self.titulus.hidesBackButton=YES;
[self seeNavBar];
//Create and add the space for user to write.
[self createSpaceToWrite];
if (self.textToSave!=@"")
{
self.textView.text = self.textToSave;
}
[self.view addSubview:self.textView];
[self.textView becomeFirstResponder];
//Keyboard notifications.
if (self.textView)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
}