NSMutableDictionary
*
sw_dict;
@interface
FindFriendEntryViewController:UIViewController<UIScrollViewDelegate, UITextFieldDelegate>
@property
(nonatomic) UITableView
*
m_tableView;
-
(
long
long
)numberOfSectionsInTableView:(
id
)tableView;
-
(void)addNotice;
@end
%
hook FindFriendEntryViewController
%
new
-
(void)addNotice {
[[NSNotificationCenter defaultCenter] addObserver:
self
selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification
object
:nil];
[[NSNotificationCenter defaultCenter] addObserver:
self
selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification
object
:nil];
}
%
new
-
(void)textFieldContentChanged:(UITextField
*
)textField {
NSLog(@
"11111== %ld"
, textField.tag);
/
/
输入文字时 一直监听
if
(textField.text.length >
=
1
) {
textField.text
=
[textField.text substringToIndex:
1
];
[textField resignFirstResponder];
}
}
%
new
-
(void)keyboardWillShow:(NSNotification
*
)note
{
CGRect keyBoardRect
=
[note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
UITableView
*
tableView
=
[
self
valueForKey:@
"m_tableView"
];
[tableView setContentOffset:CGPointMake(
0
, keyBoardRect.size.height) animated:YES];
}
%
new
-
(void)keyboardWillHide:(NSNotification
*
)note
{
UITableView
*
tableView
=
[
self
valueForKey:@
"m_tableView"
];
[tableView setContentOffset:CGPointMake(
0
,
0
) animated:YES];
}
%
new
-
(void)textFieldTextDidChange:(NSNotification
*
)notification {
UITextField
*
textField
=
[notification
object
];
if
(textField.text.length >
=
1
) {
textField.text
=
[textField.text substringToIndex:
1
];
NSString
*
key
=
sw_shaizi_key;
NSInteger num
=
[textField.text integerValue];
BOOL
isCorrect
=
(num >
0
&& num <
7
);
if
(textField.tag
=
=
201
) {
key
=
sw_caiquan_key;
isCorrect
=
(num >
0
&& num <
4
);
}
if
(isCorrect) {
[SWUserDefaults setInteger:num forKey:key];
[SWUserDefaults synchronize];
[textField resignFirstResponder];
}
else
{
NSString
*
message
=
@
"请输入1-6的数值"
;
if
(textField.tag
=
=
201
) {
message
=
@
"请输入1-3的数值"
;
}
/
/
提示从新输入
textField.text
=
nil;
UIAlertView
*
alertview
=
[[UIAlertView alloc] initWithTitle:@
"提示"
message:message delegate:
self
cancelButtonTitle:@
"好的"
otherButtonTitles:nil];
[alertview show];
}
}
}
-
(void)viewDidLoad {
%
orig;
UITableView
*
tableView
=
[
self
valueForKey:@
"m_tableView"
];
[tableView setValue:
self
forKey:@
"delegate"
];
tableView.estimatedRowHeight
=
0
;
tableView.estimatedSectionFooterHeight
=
0
;
tableView.estimatedSectionHeaderHeight
=
0
;
sw_dict
=
[NSMutableDictionary dictionary];
for
(
int
i
=
0
; i <
2
; i
+
+
) {
UITextField
*
textField
=
[[UITextField alloc] initWithFrame:CGRectMake(
0
,
7
,
65
,
40
)];
textField.borderStyle
=
UITextBorderStyleLine;
textField.textAlignment
=
NSTextAlignmentCenter;
textField.keyboardType
=
UIKeyboardTypeNumberPad;
textField.returnKeyType
=
UIReturnKeyDone;
textField.clearButtonMode
=
UITextFieldViewModeWhileEditing;
textField.delegate
=
self
;
textField.font
=
[UIFont systemFontOfSize:
14
];
[[NSNotificationCenter defaultCenter]
addObserver:
self
selector:@selector(textFieldTextDidChange:)
name:UITextFieldTextDidChangeNotification
object
:textField];
textField.tag
=
200
+
i;
if
(i
=
=
0
) {
textField.placeholder
=
@
"1-6"
;
[sw_dict setObject:textField forKey:@
"sw_shaizi_textfield"
];
}
else
{
textField.placeholder
=
@
"1-3"
;
[sw_dict setObject:textField forKey:@
"sw_caiquan_textfield"
];
}
}
[
self
addNotice];
}
-
(
long
long
)numberOfSectionsInTableView:(
id
)tableView {
return
%
orig
+
1
;
}
-
(
long
long
)tableView:(
id
)tableView numberOfRowsInSection:(
long
long
)section {
if
(section !
=
[
self
numberOfSectionsInTableView:tableView]
-
1
) {
return
%
orig;
}
return
2
;
}
-
(
id
)tableView:(
id
)tableView cellForRowAtIndexPath:(NSIndexPath
*
)indexPath {
if
([indexPath section] !
=
[
self
numberOfSectionsInTableView:tableView]
-
1
) {
return
%
orig;
}
NSString
*
cellId
=
@
"shaizi"
;
if
(indexPath.row
=
=
1
) {
cellId
=
@
"caiquan"
;
}
UITableViewCell
*
cell
=
[tableView dequeueReusableCellWithIdentifier:cellId];
if
(!cell) {
cell
=
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
cell.imageView.image
=
[UIImage imageNamed:@
"weixin_shaizi"
];
cell.textLabel.text
=
@
"骰子点数"
;
UITextField
*
textField
=
[sw_dict objectForKey:@
"sw_shaizi_textfield"
];
NSInteger num
=
[SWUserDefaults integerForKey:sw_shaizi_key];
if
(indexPath.row
=
=
1
) {
cell.imageView.image
=
[UIImage imageNamed:@
"weixin_caiquan"
];
cell.textLabel.text
=
@
"猜拳(1剪刀 2石头 3布)"
;
textField
=
[sw_dict objectForKey:@
"sw_caiquan_textfield"
];
num
=
[SWUserDefaults integerForKey:sw_caiquan_key];
}
NSString
*
str
=
[NSString stringWithFormat:@
"%ld"
, num];
textField.text
=
str
;
cell.accessoryView
=
textField;
}
cell.backgroundColor
=
[UIColor whiteColor];
return
cell;
}
-
(double)tableView:(
id
)tableView heightForRowAtIndexPath:(NSIndexPath
*
)indexPath {
if
([indexPath section] !
=
[
self
numberOfSectionsInTableView:tableView]
-
1
) {
return
%
orig;
}
return
55
;;
}
-
(void)tableView:(UITableView
*
)tableView didSelectRowAtIndexPath:(NSIndexPath
*
)indexPath {
if
([indexPath section] !
=
[
self
numberOfSectionsInTableView:tableView]
-
1
) {
return
%
orig;
}
/
/
[tableView deselectRowAtIndexPath:indexPath];
}
-
(void)touchesBegan:(NSSet<UITouch
*
>
*
)touches withEvent:(UIEvent
*
)event {
[
self
.view endEditing:YES];
}
-
(void)scrollViewWillBeginDragging:(UIScrollView
*
)scrollView {
[
self
.view endEditing:YES];
}
-
(
BOOL
)textField:(UITextField
*
)textField shouldChangeCharactersInRange:(NSRange)
range
replacementString:(NSString
*
)string
{
NSLog(@
"11111== %ld"
, textField.tag);
/
/
输入文字时 一直监听
if
(textField.text.length >
1
) {
textField.text
=
[textField.text substringToIndex:
1
];
[textField resignFirstResponder];
}
return
YES;
}
%
end