我正在爲iPhone的IRC客戶端工作,而我的UITableView出現問題。UITableView在添加元素時調整大小
首先我調整了桌面視圖的大小,以便在用戶輸入消息時,工具欄和鍵盤將適合屏幕。這樣看:
但問題是,當用戶完成輸入,並希望發送信息(發送到流並添加到tableview中)的實現代碼如下調整大小和工具欄在放底部,但鍵盤仍然存在,我不是哪個文本框辭職的第一響應者,我想保持鍵盤和工具欄在按下發送按鈕之前和之後。這樣看:
這是我的一些代碼:
-Resizing窗戶
// Keyboard will show
- (void)keyboardWillShow {
[UIView animateWithDuration:0.25 animations:^{
[self.tableView setFrame:CGRectMake(0, 0, 320, 177)];
}];
[UIView animateWithDuration:0.25 animations:^{
[self.toolBar setFrame:CGRectMake(0, 177, 320, 43)];
}];
}
// Keyboard will hide
- (void)keyboardWillHide {
[UIView animateWithDuration:0.25 animations:^{
[self.tableView setFrame:CGRectMake(0, 0, 320, 481)];
}];
[UIView animateWithDuration:0.25 animations:^{
[self.toolBar setFrame:CGRectMake(0, 393, 320, 43)];
}];
}
-Adding元素的實現代碼如下
// Retrieve the sender and the message from the input and add it to the data context
- (void)addMessage:(NSString *) input isSender: (BOOL) sender {
Message *messageToBeAdded = [[Message alloc] init];
[messageToBeAdded setIsSender:sender];
NSArray *arr = [input componentsSeparatedByString:[NSString stringWithFormat:@"PRIVMSG %@ :",[connection channel]]];
[messageToBeAdded setMessage:[arr objectAtIndex:1]];
arr = [input componentsSeparatedByString:@"!"];
if (sender) {
[messageToBeAdded setSender:[connection nick]];
} else {
NSString *tmp = [arr objectAtIndex:0];
[messageToBeAdded setSender:[tmp substringWithRange:NSMakeRange(1, [tmp length]-1)]];
}
[_messageList addObject:messageToBeAdded];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[_messageList count]-1 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
I'我已經看到無處不在,並且我確信它與添加部分o有關桌面視圖。我將不勝感激任何幫助或指導。
謝謝!
編輯: 我剛剛意識到,這與使用自定義單元格有關。我創建了一個新項目並試圖模擬我所做的一步一步。而且一切工作都很好,我用UILabel來定製單元格。 UILabel通過插座連接到UITableViewCell類,這是發生問題的地方。
#import <UIKit/UIKit.h>
@interface CustomCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *myLabel;
@end
任何想到這裏可能是錯誤的?
我認爲這個問題是missunderstood,我不希望按下發送按鈕時可以移除鍵盤。感謝迄今爲止的迴應! – RobertH 2013-04-24 20:37:03