0

1.Facebook iOS アプリで、コンテンツを入力せずに新しい投稿を開くと、右上隅の [投稿] ボタンがアクティブになりません。コンテンツを入力するとすぐにアクティブになります。その効果をどのように実装しますか?

2.セルのコンテンツとして多くのタグ名を含むページを作成したい場合、ユーザーはいくつかのタグを選択してコンテンツをフィルタリングできます。基本的に、選択されたセクションと選択されていないセクションの 2 つのセクションがあります。ユーザーが選択されていないセクションのセルに触れると、選択されたセクションに飛びます。選択したセクションに少なくとも 1 つのセルがある場合にのみ、右上隅の [GO] ボタンをアクティブにしたいと考えています (最初は、すべてのタグ名が選択されていないセクションにあります)。では、テーブルビュー セルがナビゲーション バーの [GO] ボタンに影響を与えるように実装するにはどうすればよいでしょうか。ありがとうございました!

4

2 に答える 2

0

次のコードを使用してください... コード内のコメントで説明されています。

viewDidLoad

textField.delegate = self; //sets delegate to this file so it calls the method below

ファイル.h

@interface ViewController : UIViewController <UITextFieldDelegate> //makes it so we can set the delegate

ファイル.m

- (BOOL) textField:(UITextField *)aTextField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { //method that gets called on edit
if([textField.text length] > 0) { //if contains characters
tabBarButton.enabled = YES; //set enabled
} 
else { //if not
tabBarButton.enabled = NO; //set disabled
}
return YES;
}

これらは変数であるため、それに応じtabBarButtonて変更する必要があります。textField

于 2013-07-01T02:06:30.420 に答える
0

You can use the enabled property of UIButton and detect when the button will be enabled or not.

For UITextView, probably you have a delegate method that can help you. Read all delegate methods from here. For example, you can use textViewDidChange:(UITextView *)textView method. Inside it, you can enable your button only if [textView.text length] is greater than 0.

For the second answer, you should have a model (probably an array) where you store the selected tags. The correct way of managing your button's state, should be using KVO, detecting every time the model changes and enabling the button only if there is items in the array. Another aproach should be use the same method where you add or remove items from the model, to enable or disable your button properly.

Excuse me for my english, but i hope this answer helps!

于 2013-07-01T00:53:46.250 に答える